Created
April 5, 2014 03:51
-
-
Save RussellLuo/9987264 to your computer and use it in GitHub Desktop.
A simple class for generating dot chained attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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