Accessing class-level variables

Gerhard Häring gh_pythonlist at gmx.de
Wed Apr 24 00:04:04 EDT 2002


I'm trying to access a class variable in a derived class. I sincerly
hope there's a less kludgy way than what I'm currently using:

class X:
    a = 5

class Y(X):
    def p(self):
        print self.__class__.a

Y().p()

Gerhard
-- 
This sig powered by Python!
Außentemperatur in München: 9.7 °C      Wind: 2.2 m/s





More information about the Python-list mailing list