Skip to content

Instantly share code, notes, and snippets.

@romanz
Created October 4, 2011 10:15
Show Gist options
  • Save romanz/1261305 to your computer and use it in GitHub Desktop.
Save romanz/1261305 to your computer and use it in GitHub Desktop.
Attribute dictionary
class Dict(dict):
''' Extends Python dictionary for attribute access, so d.foo is the same as d['foo']. '''
def __setattr__(self, name, val):
dict.__setitem__(self, name, val)
def __getattr__(self, name):
return dict.__getitem__(self, name)
def __delattr__(self, name):
return dict.__delitem__(self, name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment