Python 2.3.3 super() behaviour

Nicolas Lehuen nicolas.lehuen at thecrmcompany.com
Wed Apr 21 05:16:07 EDT 2004


Hi,

I hope this is not a FAQ, but I have trouble understanding the behaviour of
the super() built-in function. I've read the excellent book 'Python in a
Nutshell' which explains this built-in function on pages 89-90. Based on the
example on page 90, I wrote this test code :

class A(object):
    def test(self):
        print 'A'

class B(object):
    def test(self):
        print 'B'

class C(A,B):
    def test(self):
        super(C,self).test()
        print 'C'

print C.__mro__
c=C()
c.test()

The output is :
(<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <type
'object'>)
A
C

Whereas I was expecting :
(<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <type
'object'>)
A
B
C

Was I wrong to expect this (based on what I've read ?)

Regards,
Nicolas







More information about the Python-list mailing list