Class methods
Fredrik Lundh
fredrik at pythonware.com
Wed Oct 5 15:02:09 EDT 2005
Class methods"Hughes, Chad O" wrote:
> Is there any way to create a class method?
somewhat ironically, the first google hit for that sentence is a chapter in the
python tutorial that *doesn't* explain how to create class methods...
as others have pointed out, the classmethod wrapper/descriptor is (probably)
what you want. some additional reading:
http://www.python.org/2.2/descrintro.html#staticmethods
http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing
http://soiland.no/software/decorator
also note that you may find that using a function at the module level leads to
nicer code than using a classmethod/staticmethod, especially if you look at
things from the caller's perspective.
</F>
More information about the Python-list
mailing list