Can I define "static" (like in C++) methods in Python?

Erik Max Francis max at alcyone.com
Thu Apr 10 20:18:43 EDT 2003


sdieselil wrote:

> Can I define methods which are attributes of class and not attributes
> of
> instance?

>>> class C:
...  X = 1 # X is a class attribute
...  def __init__(self, y):
...   self.y = y # y is an instance attribute
... 
>>> C.X
1
>>> c = C(10)
>>> c.X
1
>>> c.y
10
>>> C.X = 2
>>> c.X
2
>>> c.y 
10

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ We're here to preserve democracy, not to practice it.
\__/ Capt. Frank Rasmey
    REALpolitik / http://www.realpolitik.com/
 Get your own customized newsfeed online in realtime ... for free!




More information about the Python-list mailing list