Skip to content

Instantly share code, notes, and snippets.

@nicwolff
Created October 26, 2015 21:56
Show Gist options
  • Select an option

  • Save nicwolff/c3f40e34e1652fc4bfde to your computer and use it in GitHub Desktop.

Select an option

Save nicwolff/c3f40e34e1652fc4bfde to your computer and use it in GitHub Desktop.
Python dict subclass that can be indexed with object.attribute syntax
class dotdict(dict):
def __getattr__(self, attr):
return self[attr]
def __missing__(self, key):
self[key] = dotdict()
return self[key]
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment