Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created November 30, 2011 21:39
Show Gist options
  • Select an option

  • Save shreyansb/1411033 to your computer and use it in GitHub Desktop.

Select an option

Save shreyansb/1411033 to your computer and use it in GitHub Desktop.
print whenever a class's attributes are accessed
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
@shreyansb
Copy link
Copy Markdown
Author

Thanks @j2labs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment