Skip to content

Instantly share code, notes, and snippets.

@elyezer
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elyezer/11535316 to your computer and use it in GitHub Desktop.
Save elyezer/11535316 to your computer and use it in GitHub Desktop.
How to do some additional processing for class attributes
class ApiMeta(type):
def __getattr__(cls, name):
print name
super(ApiMeta, cls).__getattr__(name)
class A(object):
__metaclass__ = ApiMeta
A.some_attr
$ python metagetattr.py
some_attr
Traceback (most recent call last):
File "metagetattr.py", line 9, in <module>
A.some_attr
File "metagetattr.py", line 4, in __getattr__
super(ApiMeta, cls).__getattr__(name)
AttributeError: 'super' object has no attribute '__getattr__'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment