Static class methods
Daniel Klein
danielk at aracnet.com
Mon Mar 5 10:12:54 EST 2001
On Sun, 4 Mar 2001 14:22:10 -0800, "Alex Shindich" <alex at shindich.com> wrote:
>Just out of my curiosity, have any of you ladies and gentlemen experienced a
>need for an equivalent of C++/Java static method?
>Because I have, but it is impossible add them to Python classes -- all class
>methods are treated as instance methods.
The Quick Python Book by Daryl Harms and Kenneth McDonald outlines a way to
accomplish this by breaking out the class into its own module and then define
the 'class methods' as top-level functions.
myclass.py
def myClassMethod():
# do some class thing
class Foo:
def __init__(self):
pass
def bar(self):
pass
Daniel Klein
More information about the Python-list
mailing list