例1:非菱形继承,经典类与新式类的属性查找顺序都一样
# class E:
# # def test(self):
# # print('from E')
# pass
#
# class F:
# def test(self):
# print('from F')
#
#
# class B(E):
# # def test(self):
# # print('from B')
# pass
#
# class C(F):
# def test(self):
# print('from C')
#
#
# class D:
# def test(self):
# print('from D')
#
#
# class A(B, C, D):
# # def test(self):
# # print('from A')
# pass
#
# obj=A()
# obj.test()
# class E:
# # def test(self):
# # print('from E')
# pass
#
# class F:
# def test(self):
# print('from F')
#
#
# class B(E):
# # def test(self):
# # print('from B')
# pass
#
# class C(F):
# def test(self):
# print('from C')
#
#
# class D:
# def test(self):
# print('from D')
#
#
# class A(B, C, D):
# # def test(self):
# # print('from A')
# pass
#
# obj=A()
# obj.test()
# 例2:菱形继承
class G(object): # 在python2中,未继承object的类及其子类,都是经典类
# def test(self):
# print('from G')
pass
class G(object): # 在python2中,未继承object的类及其子类,都是经典类
# def test(self):
# print('from G')
pass
class E(G):
# def test(self):
# print('from E')
pass
# def test(self):
# print('from E')
pass
class F(G):
# def test(self):
# print('from F')
pass
# def test(self):
# print('from F')
pass
class B(E):
# def test(self):
# print('from B')
pass
# def test(self):
# print('from B')
pass
class C(F):
# def test(self):
# print('from C')
pass
# def test(self):
# print('from C')
pass
class D(G):
# def test(self):
# print('from D')
pass
# def test(self):
# print('from D')
pass
class A(B,C,D):
# def test(self):
# print('from A')
pass
# def test(self):
# print('from A')
pass
# obj=A()
# obj.test()
# obj.test()
print(A.mro())