[Tutor] Re: special object method for method calls?
Jeff Shannon
jeff at ccvcorp.com
Tue Nov 11 22:43:03 EST 2003
Abel Daniel wrote:
> 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.
Hm, you're right. That's odd, I'd have *sworn* that __getattr__()
could be used to intercept lookups of existing attributes. Or at
least that *something* could be. Unfortunately I don't have time to
track this down right now...
Jeff Shannon
Technician/Programmer
Credit International
More information about the Tutor
mailing list