Python's equivalent of static member data?

P at draigBrady.com P at draigBrady.com
Thu May 8 06:10:33 EDT 2003


Bram Stolk wrote:
> Hello,
> 
> In C++, you can have static member data: only one instance of the data,
> shared by all instances of the class.
> 
> What is the equivalent in Python?
> 
> Thanks,
> 
>   Bram
> 
> 

class attributes are the equivalent:

class myClass:
     static1 = 1
myObject=myClass()
myClass.static2=2

assert(myOject.static1==1)
assert(myOject.static2==2)

Pádraig.





More information about the Python-list mailing list