Created
December 6, 2011 13:19
-
-
Save Apkawa/1438185 to your computer and use it in GitHub Desktop.
KeyAttribytedDict
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
class KeyAttributeDict(dict): | |
''' | |
>>> kd = KeyAttributeDict({'a':1}) | |
>>> kd['a'] | |
1 | |
>>> kd.a | |
1 | |
''' | |
def __getattribute__(self, name): | |
try: | |
return object.__getattribute__(self, name) | |
except AttributeError, error: | |
return self[name] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment