grandparent method with super

kyosohma at gmail.com kyosohma at gmail.com
Thu Apr 5 22:29:52 CEST 2007


On Apr 5, 3:19 pm, Martin Manns <mma... at gmx.de> wrote:
> Hi,
>
> I have a class structure as follows and I would like to invoke the
> method A.m() from D.m
>
> class A(object):
>         def m(self):
> class B(A):
>         def m(self):
> class C(A):
>         def m(self):
> class D(B,C):
>         def m(self):
>                 # Call A.m with super?
>
> I have readhttp://www.python.org/download/releases/2.2/descrintro/but
> I am still stuck.
>
> Thanks in advance
>
> Martin

I'm not sure if this is what you want, but it's my best guess:

class A(object):
        def m(self):
            print "I'm the original"
class B(A):
        def m(self):
            print 'B class here'
class C(A):
        def m(self):
            print 'C class here'
class D(B,C):
        def m(self):
                x = A()
                x.m()

temp = D()
temp.m()



Mike




More information about the Python-list mailing list