Closures in metaclasses
__peter__ at web.de
Thu Jan 21 21:55:09 CET 2010
> I tried overriding __getattr__ and got an error at runtime (the
You can either move __getattr__() into the metaclass or instantiate the
class. I prefer the latter.
Both approaches in one example:
>>> class Tag:
... class __metaclass__(type):
... def __getattr__(self, name): return "<%s> via metaclass" %
... def __getattr__(self, name): return "<%s> via class" % name
'<yadda> via metaclass'
>>> tag = Tag()
'<yadda> via class'
More information about the Python-list