N
Nicolas Lehuen
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
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