Python super usage example
Python docs for super say:return a proxy object that delegates method calls to a parent or sibling class of type
http://docs.python.org/2/library/functions.html 355;superfure
有人能给我一个
使用三角形继承模式时:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | >>> class A(object): ... def __init__(self): ... print 'A.__init__()' ... super(A, self).__init__() ... >>> class B(object): ... def __init__(self): ... print 'B.__init__()' ... super(B, self).__init__() ... >>> class C(A, B): ... def __init__(self): ... print 'C.__init__()' ... super(C, self).__init__() ... >>> C() C.__init__() A.__init__() B.__init__() <__main__.C object at 0x10f27e190> |
在这里,
1 2 | >>> C.__mro__ (<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <type 'object'>) |
号
因此,