Skip to content

Instantly share code, notes, and snippets.

@andelf
Created October 24, 2011 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andelf/1308269 to your computer and use it in GitHub Desktop.
Save andelf/1308269 to your computer and use it in GitHub Desktop.
A free dict as a property container
class Data(dict):
def __init__(self, *args, **kwargs):
super(Data, self).__init__(*args, **kwargs)
self.__dict__ = self
a = Data()
a = Data(name="Tom", age=17)
print a
# -> {'age': 17, 'name': 'Tom'}
a.sex = "male"
print a
# -> {'age': 17, 'name': 'Tom', 'sex': 'male'}
d = Data(name="Foo")
print d.items()
# -> ...
d.items = "Bar"
print d.items()
# ops!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment