Skip to content

Instantly share code, notes, and snippets.

@DamianZaremba
Created July 16, 2011 21:25
Show Gist options
  • Save DamianZaremba/1086806 to your computer and use it in GitHub Desktop.
Save DamianZaremba/1086806 to your computer and use it in GitHub Desktop.
Demo of using __dict__ to pull stuff out of objects.
DamiansMacBookPro:patchwork damian$ python
clPython 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Boob(object):
... someawesomething = "nipple"
...
>>> abc = Boob()
>>> print(abc.someawesomething)
nipple
>>> print abc.__dict__
{}
>>> print Boob.__dict__
{'__dict__': <attribute '__dict__' of 'Boob' objects>, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'Boob' objects>, '__doc__': None, 'someawesomething': 'nipple'}
>>> abc.thisval = "awesome"
>>> print abc.__dict__
{'thisval': 'awesome'}
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment