Does anybody has a good example of how to use super() to Pass Control to Other Classes?
我刚刚了解到,
通常可以通过执行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | class Base(object): def foo(self): print 'Base' class Child1(Base): def foo(self): super(Child1, self).foo() print 'Child1' class Child2(Base): def foo(self): super(Child2, self).foo() print 'Child2' class GrandChild(Child1, Child2): def foo(self): super(Child2, self).foo() print 'GrandChild' Base().foo() # outputs: # Base Child1().foo() # outputs: # Base # Child1 Child2().foo() # outputs: # Base # Child2 GrandChild().foo() # outputs: # Base # Child1 # Child2 # GrandChild |
您可以在文档中通过谷歌搜索"diamond inheritance"或"diamond inheritance python"找到更多信息。