Static Methods in Python

2005-05-01 Thread Kris
Hi,
  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.

Thanks,
Kris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static Methods in Python

2005-05-01 Thread John Roth

Kris [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Hi,
  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.

Generally, there's very little need for static methods in  Python. That
niche is better handled by module level functions. You can use real
static methods with new style classes, using the staticmethod built
in function. However, you can't reference class variables with
static methods - you should use class methods to do that. See the
Python library documentation.

John Roth

 Thanks,
 Kris
 

-- 
http://mail.python.org/mailman/listinfo/python-list