Skip to content

Instantly share code, notes, and snippets.

@johnboxall
Created October 1, 2009 05:25
Show Gist options
  • Save johnboxall/198745 to your computer and use it in GitHub Desktop.
Save johnboxall/198745 to your computer and use it in GitHub Desktop.
>>> class User(object):
... username = "bob"
...
>>> class SuperUser(object):
... position = "super"
...
... def __init__(self, user):
... self.user = user
...
... def __getattr__(self, attr):
... return getattr(self.user, attr)
...
>>> user = User()
>>> superuser = SuperUser(user)
>>> superuser.position
'super'
>>> superuser.username
'bob'
>>> superuser.unknown
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 8, in __getattr__
AttributeError: 'User' object has no attribute 'unknown'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment