__getattr__ and __setattr__ troubles
Boudewijn Rempt
boud at rempt.xs4all.nl
Wed May 24 12:01:05 EDT 2000
Niels Diepeveen <niels at endea.demon.nl> wrote:
> Boudewijn Rempt schreef:
>> From the documentation I understood that __getattr__ is only called when
>> the ordinary normal mechanism fails. However, I see it being called even
>> when my app needs things like __cmp__ and __repr__. though not for the
>> fields I added myself after creating the object.
> That's right. The normal mechanism for attribute lookup is to look in
> __dict__. If that does not work __getattr__ is called. This goes for
> methods as well as any other attributes.
Thanks! That was the solution. I'm still a bit surprised that
__getattr__ was actually called for __cmp__, but there are logical
reasons for that, I'm sure.
--
Boudewijn Rempt | http://www.valdyas.org
More information about the Python-list
mailing list