[Tutor] Re: special object method for method calls?
Abel Daniel
abli at freemail.hu
Tue Nov 11 21:49:40 EST 2003
Jeff Shannon writes:
> def __getattr__(self, attr):
> if iscallable(self.__dict__[attr]):
> # do whatever here
> return self.__dict__[attr]
This won't work. From http://python.org/doc/current/ref/attribute-access.html:
"Note that if the attribute is found through the normal
mechanism, __getattr__() is not called."
So calling self.__dict__[attr] in __getattr__ will result in a
KeyError.
--
Abel Daniel
More information about the Tutor
mailing list