マルチ継承補完
3851 ワード
オブジェクト向けマルチ継承
転載先:https://www.cnblogs.com/kangqi452/p/11617539.html
1. __mro__ c3
(1 )__mro__:
python , , 。
, __mro__ 。
(2) c3
ss A(object):
pass
class B(A):
pass
class C(B):
pass
class D(object):
pass
class E(D,C):
pass
class F(object):
pass
class G(F):
pass
class H(C,G):
pass
class Foo(E,H):
pass
# print(E.__mro__)
# print(H.__mro__)
"""
L(Foo + L(E) + L(H) )
L(E) = E,D,C,B,A,object
L(H) = H,C,B,A,G,F,object
Foo = (object) + (G,F,object)
Foo,E,D,H,C,B,A,G,F,object
"""
print(Foo.__mro__)
2.
a.
class A(object):
pass
class B(object):
def f1(self):
print('B')
class C(A, B):
pass
obj = C()
obj.f1()
b.
py2:
:
: object,
py3:
.
, ( ).
, C3 (python2.3 c3 )
Foo + (C,D,F,G) + (G,D,G,W) + (I,G,D,G,W)
FOO,
, ,
,
, ( )
, .( c3 )
:
super __mro__
転載先:https://www.cnblogs.com/kangqi452/p/11617539.html