Skip to content

Instantly share code, notes, and snippets.

@bbrodriges
Created November 14, 2012 06:43
Show Gist options
  • Save bbrodriges/4070691 to your computer and use it in GitHub Desktop.
Save bbrodriges/4070691 to your computer and use it in GitHub Desktop.
Dictionary with key/values as attributes
class AttrDict(dict):
""" A dict that allows for object-like property access syntax. """
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
def __setattr__(self, key, value):
self.update({key:value})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment