Created
October 4, 2011 10:15
-
-
Save romanz/1261305 to your computer and use it in GitHub Desktop.
Attribute dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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