Skip to content

Instantly share code, notes, and snippets.

@mstarkman
Created January 3, 2012 16:56
Show Gist options
  • Save mstarkman/1555776 to your computer and use it in GitHub Desktop.
Save mstarkman/1555776 to your computer and use it in GitHub Desktop.
Python Meta-programming Gotcha with __getattr__
class Example(object):
@property
def foo(self):
return 'bar'
@property
def boom(self):
raise AttributeError
def __getattr__(self, name):
return 'Trying to get the {0} property.'.format(name)
v = Example()
print v.foo
>>> 'bar'
print v.boom
>>> 'Trying to get the boom property.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment