classmethod & staticmethod

Neil Cerutti horpner at yahoo.com
Tue Jul 24 13:04:27 EDT 2007


On 2007-07-24, Alex Popescu <nospam.themindstorm at gmail.com> wrote:
> Bruno Desthuilliers <bruno.42.desthuilliers at wtf.websiteburo.oops.com> wrote 
> in news:46a5b2ad$0$18903$426a74cc at news.free.fr:
>
>
>>
>> [snip...]
>>
>> 
>> Not necessarily - you can access class attributes from within an 
>> instance method (but obviously a classmethod cannot access instance 
>> attributes).
>>
>
> What I am doing wrong here then:
>
> class MyClass(object):
>   class_list = ['a', 'b']
>
>   def instance_method(self):
>     print "instance_method with class list %s" % class_list

There's no implicit self or class for Python identifiers.

The name class_list must be quailified: self.class_list or
MyClass.class_list.

-- 
Neil Cerutti



More information about the Python-list mailing list