The __getattr__ magic method __getattr__ called when the attribute does not exist in the instance / class / parent classes. You would use it to create a special exception for the missing attribute:
class Foo(object): def __getattr__(self, attr):
If you want to configure access to class attributes, you need to define __getattr__ in the metaclass / type:
class BooType(type): def __getattr__(self, attr): print attr return attr class Boo(object): __metaclass__ = BooType boo = Boo() Boo.asd
If you want to configure access to attributes, use the __getattribute__ magic method.
agf
source share