Skip to content

Instantly share code, notes, and snippets.

@mythmon
Created September 11, 2012 20:50
Show Gist options
  • Select an option

  • Save mythmon/3701941 to your computer and use it in GitHub Desktop.

Select an option

Save mythmon/3701941 to your computer and use it in GitHub Desktop.
Oh no, why would you ever do this?
>>> class Foo(object):
... def __getattr__(self, name):
... if name.startswith("magic_"):
... rest = name[6:]
... def m():
... return rest
... return m
... else:
... return self.__getattribute__(name)
...
>>> f = Foo()
>>> f.magic_hands()
'hands'
>>> f.magic_fingers()
'fingers'
>>> f.wat()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 9, in __getattr__
AttributeError: 'Foo' object has no attribute 'wat'
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment