Created
November 30, 2011 21:39
-
-
Save shreyansb/1411033 to your computer and use it in GitHub Desktop.
print whenever a class's attributes are accessed
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 Desc(object): | |
| def __init__(self): | |
| self.x = 'x' | |
| def foo(self): | |
| print 'foo' | |
| def __getattribute__(self, name): | |
| print 'NAME:', name | |
| attr = object.__getattribute__(self, name) | |
| if callable(attr): | |
| print 'CALLABLE' | |
| else: | |
| print 'NOT CALLABLE' | |
| return attr | |
| d = Desc() | |
| d.foo() | |
| print d.x |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @j2labs