how to define a static field of a given class

Rob Williscroft rtw at freenet.co.uk
Fri Jun 2 05:28:25 EDT 2006


feel_energetic wrote in news:1149239221.045268.6170
@g10g2000cwb.googlegroups.com in comp.lang.python:

> Hi,
> 
>     I already knew how to define a static method of a class( using
> staticmethod() ),but I find there isn't a built-in func to build a
> static field ( something like staticfield() )
>     can anyone help me on this?
>     thanks very much for your help :)
> 

What you possibly want is just a class attribute:

class MyClass( object ):
  static_field = 10
  
myInstance = MyClass()

print MyClass.static_field, myInstance.static_field

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list