Skip to content

Instantly share code, notes, and snippets.

@darkf
Created October 31, 2014 09:55
Show Gist options
  • Save darkf/d532edb0ac4307c8725c to your computer and use it in GitHub Desktop.
Save darkf/d532edb0ac4307c8725c to your computer and use it in GitHub Desktop.
JS-style lookups for Python dicts
class dotdict(dict):
def __getattribute__(self, key):
if key in self:
return self[key]
return dict.__getattribute__(self, key)
d = dotdict(a=1, b=2)
print d.a, d.b
print d.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment