Faqts : Computers : Programming : Languages : Python : Language and Syntax : "New Style" (2.2) classes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 6 people (83%) answered Yes
Recently 5 of 6 people (83%) answered Yes

Entry

Is there a way I can use staticmethod and classmethod in Python 2.1?
How can I create "static" (class-level, not instance-level) methods?

Jun 7th, 2002 09:42
Michael Chermside,


Python 2.2 has staticmethod and classmethod, which are used to create
methods that belong more to the CLASS itself than to the instance.
Two good places to read about this feature are:
   http://www.etsimo.uniovi.es/python/2.2/descrintro.html
and
   http://www.amk.ca/python/2.2/
If you are still using Python 2.1 or earlier, than these won't help you,
but there are still possible work-arounds: Staticmethod can be emulated
quite well in python 2.1:
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52304
Classmethod is a little more of a problem, but here is a solution that
requires only minimal modification of code:
    http://groups.google.com/groups?th=4565ae6f1f3979cf