staticmethod makes my brain hurt

Dotan Cohen dotancohen at gmail.com
Thu Nov 17 06:13:38 EST 2011


On Thu, Nov 17, 2011 at 09:37, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Wed, Nov 16, 2011 at 11:44 PM, Dotan Cohen <dotancohen at gmail.com> wrote:
>> Try this (untested):
>>
>> class C:
>>   @staticmethod
>>   def foo():
>>       pass
>>
>>   print "inside", C.foo, callable(C.foo)
>
> If you had tested this, you would have found that you get a NameError,
> since C is not yet bound inside the class block where you define it.
>

I hadn't tested, I'm at work far from Idle. Just shooting from the hip.

For that matter, though, this does work in Java (I'm pretty sure but
again, untested right now).

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com



More information about the Python-list mailing list