__getattr__ question

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Jun 9 20:13:59 EDT 2006


Laszlo Nagy <gandalf at designaproduct.biz> writes:

> This is from the Python documentation (fragment):
> 
> __getattr__(     self, name)
>     Called when an attribute lookup has not found the attribute in the 
> usual places (i.e. it is not an instance attribute nor is it found in 
> the class tree for self). name is the attribute name. This method should 
> return the (computed) attribute value or raise an AttributeError exception.
> 
> 
> How can I determine if an attribute can be found in the usual places? 

When the attribute is not found in the usual places, the object's
__getattr__ method (if it has one) is called. Thus, when you write
your __getattr__ method, you should assume that the attribute has not
been found in the usual places.

-- 
 \         "If nature has made any one thing less susceptible than all |
  `\    others of exclusive property, it is the action of the thinking |
_o__)                       power called an idea"  -- Thomas Jefferson |
Ben Finney




More information about the Python-list mailing list