Static Methods in Python

John Roth newsgroups at jhrothjr.com
Sun May 1 22:16:40 EDT 2005


"Kris" <iamkris at gmail.com> wrote in message 
news:1114999599.608054.52730 at f14g2000cwb.googlegroups.com...
> 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
> 




More information about the Python-list mailing list