Python equivalent of static member data?

Emile van Sebille emile at fenx.com
Sat Feb 10 17:32:24 EST 2001


I'm not familiar with C++ static members, but it sounds like
you are looking for something like:

class Test:
    instances = 0
    def __init__(self, incBy=1):
        Test.instances = Test.instances + incBy
        print Test.instances

a = Test()
b = Test(2)


HTH,

--

Emile van Sebille
emile at fenx.com
-------------------


"Roger H" <rhyde99 at email.msn.com> wrote in message
news:#USeY36kAHA.359 at cpmsnbbsa07...
> I've just gotten done digging through the docs for 1.5.2,
> and did not find an answer to my question:  Is there a
> Python equivalent to the C++ concept of static member
> data?  I'd like to make a class, and have each instance
> of that class share a variable and its associated value.
> Each instance would have the ability to modify that value,
> and the new value would be updated through all instances.
>
> Make sense?
>
> ~Roger the Shrubber~
>
>





More information about the Python-list mailing list