[Tutor] __getattr__ can't be a staticmethod?

Kent Johnson kent37 at tds.net
Sat May 24 04:47:01 CEST 2008


On Fri, May 23, 2008 at 7:52 PM, inhahe <inhahe at gmail.com> wrote:
> why doesn't this work?
>
>>>> class a:
> ...   @staticmethod
> ...   def __getattr__(attr):
> ...     return "I am a dork"
> ...
>>>> f = a()
>>>> f.hi
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: 'staticmethod' object is not callable

I don't know why you are getting that specific error, but what are you
trying to do? This code doesn't make sense. __getattr__() is the hook
for getting attributes of an object; staticmethods aren't associated
with any object. What attributes do you want to get?

Kent


More information about the Tutor mailing list