Skip to content

Instantly share code, notes, and snippets.

@Apkawa
Created December 6, 2011 13:19
Show Gist options
  • Save Apkawa/1438185 to your computer and use it in GitHub Desktop.
Save Apkawa/1438185 to your computer and use it in GitHub Desktop.
KeyAttribytedDict
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