Created
January 3, 2012 16:56
-
-
Save mstarkman/1555776 to your computer and use it in GitHub Desktop.
Python Meta-programming Gotcha with __getattr__
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 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