__getattr__ question

Andrew Robert andrew.arobert at gmail.com
Sat Jun 10 03:24:27 CEST 2006


If I remember correctly, this behavior depends on how the class is
created (classic mode versus modern).

Modern

	class foo(object):
    		pass

Classic ( pre python 2.2 I believe )

	class foo():
    		pass

The modern method of specifying object in the class definition gets all
of the class attributes cleanly.

The classic method does not have this so the behavior is simulated.


Ben Finney wrote:
> 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.
> 



More information about the Python-list mailing list