Static Methods in Python

Erik Max Francis max at alcyone.com
Sun May 1 22:12:24 EDT 2005


Kris wrote:

>   I am a newbie to Python. With a background in Java, I was attempting
> to write static methods in the class without the self as the first
> parameter, when I got an error. I did a search for the same on Google
> and found out that there was no consistent approach to this. I would
> like to know what is the prescribed approach for the same. Any
> thoughts, pointers about the same would be very much appreciated.

Do something like (2.4):

	@staticmethod
	def aStaticMethod(x, y, z):
	    ...

Prior to 2.4, use:

	def aStaticMethod(x, y, z):
	    ...
	aStaticMethod = staticmethod(aStaticMethod)

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Wyrd has swept all my kin / all the brave chiefs away! / Now I must
   follow them! -- Beowulf



More information about the Python-list mailing list