How can I call a subclass method from parent class ?

bonono at gmail.com bonono at gmail.com
Thu Oct 20 05:55:40 CEST 2005


Hi,

Suppose my class definition is like this :

class A:
    name = "A"

    @classmethod
    def foo(cls):
        cls.__super.foo()
        cls.bar()

    @classmethod
    def bar(cls):
        print cls.name

class B(A):
    name = "B"

class C(B):
    name = "C"

What I want is

C.foo() prints 'ABC'
B.foo() prints 'BC'
A.foo() prints 'A'

But when I call C.foo(), it said

AttributeError: class C has no attribute '_A__super'

How should this be coded ?




More information about the Python-list mailing list