March 2003
Intermediate to advanced
656 pages
39h 30m
English
__getattr__
__getattr__(self,name)When attribute
x.y
is accessed but not found by the usual procedure (i.e., where
AttributeError would normally be raised), Python
calls x
.__getattr__('y')
instead. Python does not call __getattr__ for
attributes found by normal means (i.e., as keys in
x
.__dict__ or via
x
.__class__). If you
want Python to call __getattr__ on every
attribute reference, keep the attributes elsewhere (e.g., in another
dictionary referenced by an attribute with a private name, as shown
earlier in this chapter), or else write a new-style class and
override __getattribute__ instead. __getattr__ should raise AttributeError
if it cannot find y.
Read now
Unlock full access