classmethod & staticmethod

Alex Popescu nospam.themindstorm at gmail.com
Tue Jul 24 17:35:58 EDT 2007


Neil Cerutti <horpner at yahoo.com> wrote in
news:slrnfaccgl.1gk.horpner at FIAD06.norwich.edu: 

> 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...]
>
>>
>> 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.
> 

After more investigation I have figured this out by myself, but thanks for 
the details.
Now I am wondering if in the above case there is a prefered way:
MyClass.class_list or self.__class__.class_list? (IMO the 2nd is more safe 
in terms of refactorings).

./alex
--
.w( the_mindstorm )p.




More information about the Python-list mailing list