Case Study __getattr__Otto Allmendinger exaggerates its use. You simply define all the other attributes, and if they are missing, Python will return to __getattr__.
Example:
class C(object):
def __init__(self):
self.foo = "hi"
self.bar = "mom"
def __getattr__(self, attr):
return "hello world"
c = C()
print c.foo
print c.bar
print c.baz
print c.qux
source
share