Created
July 16, 2011 21:25
-
-
Save DamianZaremba/1086806 to your computer and use it in GitHub Desktop.
Demo of using __dict__ to pull stuff out of objects.
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
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