__getattr__ and __getattribute__

Daniel Nogradi nogradi at gmail.com
Tue May 8 18:18:45 EDT 2007


> i find it difficult to understand the difference between the magic methods
> __getattr__ and __getattribute__
> and so donot know when to use former or later.

>From the docs:

__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).

__getattribute__(self, name) Called unconditionally to implement
attribute accesses for instances of the class.

Please see http://docs.python.org/ref/new-style-attribute-access.html
and http://docs.python.org/ref/attribute-access.html

HTH,
Daniel



More information about the Python-list mailing list