MRO_C3

class A:
    pass
class B(A):
    pass
class C(A):
    pass
class D(B, C):
    pass
class E(C, A):
    pass
class F(D, E):
    pass
class M:
    pass
class N(M):
    pass
class P(E, A):
    pass
class X:
    pass
class Q(P,N,X):
    pass
class G(Q, F):
    pass
class H(G, F):
    pass

'''
L(H) = H + L(G) + L(F) + GF # HGQPFDBECANMX
 
L(G) = G + L(Q) + L(F) + QF # GQPFDBECANMX 
L(Q) = Q + L(P) + L(N) + X + PNX # QPECANMX
L(P) = P + L(E) + A + EA  # PECA
L(E) = E + L(C) + A + CA   # ECA
L(C) = C + A + A   # CA
L(N) = N + M # NM

L(F) = F + L(D) + L(E) + DE # FDBECA
L(D) = D + L(B) + L(C) + BC # DBCA


'''

'''
    求H的MRO
    设求MRO的算法是L
    L(H) = H + L(G) + L(F) + GF
    L(G) = G + L(E) + E
    L(E) = E + L(C) + L(A) + CA
    L(C) = C + L(A) + A
    L(A) = A
    L(F) = F + L(D) + L(E) + DE
    L(D) = D + L(B) + L(C) + BC
    L(B) = B + L(A) + A

    # 加法:merge(), 拿第一项的第一位和 后面每项的除了第一位比较. 如果没有出现, 则该位元素算出
        如果出现了. 此时开始下一项的第一位继续和后面每一项的除了第一位比较:
        
        用头和后面身体比较
            
    L(H) = H + L(G) + L(F) + GF # ECA + DBECA  = HGFDBECAO
    L(G) = G + L(E) + E # GECA
    L(E) = E + L(C) + L(A) + CA # ECA
    L(C) = C + L(A) + A  # CA
    L(A) = A
    L(F) = F + L(D) + L(E) + DE # FDBECA
    L(D) = D + L(B) + L(C) + BC # DBCA
    L(B) = B + A + A   # BA
'''
print(H.__mro__)

  

posted on 2018-12-27 21:40  =.===  阅读(138)  评论(0编辑  收藏  举报

导航