Skip to content

Instantly share code, notes, and snippets.

@RussellLuo
Created April 5, 2014 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RussellLuo/9987264 to your computer and use it in GitHub Desktop.
Save RussellLuo/9987264 to your computer and use it in GitHub Desktop.
A simple class for generating dot chained attributes
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class DotChainedAttrs(object):
def __getattr__(self, name):
__dict__ = object.__getattribute__(self, '__dict__')
if name not in __dict__:
__dict__[name] = DotChainedAttrs()
return __dict__[name]
if __name__ == '__main__':
person = DotChainedAttrs()
person.home.address.no = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment