Static members?

Fredrik Lundh fredrik at effbot.org
Sun Jan 21 12:04:03 EST 2001


fray_fernando at my-deja.com wrote:
> How do you define a class that has an attribute common to all instances
> of this class? Something like the static members in C++

    http://www.python.org/doc/FAQ.html#4.84
    "How do I create static class data and static class
    methods?"

    class C:
        count = 0   # number of times C.__init__ called

        def __init__(self):
            C.count = C.count + 1

        def getcount(self):
            return C.count  # or return self.count

Cheers /F








More information about the Python-list mailing list