• 博客访问： 445096
• 博文数量： 72
• 博客积分： 1851
• 博客等级： 上尉
• 技术积分： 1464
• 用 户 组： 普通用户
• 注册时间： 2010-09-16 17:50

2013年（1）

2012年（17）

2011年（51）

2010年（3）

2012-12-28 20:46:01

1) precC:类C的局部顺序
2) prec:局部顺序的并集

1. L(7) = {'object'}
2. L(4) = {'4','7'}
3. L(5) = {'5','7'}
4. L(6) = {'6','7'}
5. L(2) = {'2','4','5','7','object'}
6. L(3) = {'3','4','6','7','object'}
7. L(1) = {'1','2','3','4','5','6','7','object'}
python 代码如下:

1. #! /usr/bin/env python
2. #
3. # multi inheritance view
4. # /------ 7-------\
5. # / | \
6. # 4 - 5 6
7. # \\ / /
8. # 2-/\--- 3------/
9. # \ /
10. # 0,1
11. #
12. #

13. class C7(object):
14.     def test(self):
15.         print 'test in C7'

16. class C4(C7):
17.     def test(self):
18.         print 'test in C4'

19. class C5(C7):
20.     def test(self):
21.         print 'test in C5'

22. class C6(C7):
23.     def test(self):
24.         print 'test in C6'

25. class C2(C4,C5):
26.     def test(self):
27.         print 'test in C2'

28. class C3(C4,C6):
29.     pass

30. class C1(C2,C3):
31.     pass

32. class C0(C2,C3):
33.     def test(self):
34.         print 'test in C0'
35.         super(C3,self).test()

36. if __name__ == "__main__":
37.
38.     c1 = C1()
39.     c1.test()
40.     c0 = C0()
41.     c0.test()
42.     print C7.__mro__
43.     print C6.__mro__
44.     print C5.__mro__
45.     print C4.__mro__
46.     print C3.__mro__
47.     print C2.__mro__
48.     print C1.__mro__
49.     print C0.__mro__

1. test in C2
2. test in C0
3. test in C4
4. (<class '__main__.C7'>, <type 'object'>)
5. (<class '__main__.C6'>, <class '__main__.C7'>, <type 'object'>)
6. (<class '__main__.C5'>, <class '__main__.C7'>, <type 'object'>)
7. (<class '__main__.C4'>, <class '__main__.C7'>, <type 'object'>)
8. (<class '__main__.C3'>, <class '__main__.C4'>, <class '__main__.C6'>, <class '__main__.C7'>, <type 'object'>)
9. (<class '__main__.C2'>, <class '__main__.C4'>, <class '__main__.C5'>, <class '__main__.C7'>, <type 'object'>)
10. (<class '__main__.C1'>, <class '__main__.C2'>, <class '__main__.C3'>, <class '__main__.C4'>, <class '__main__.C5'>, <class '__main__.C6'>, <class '__main__.C7'>, <type 'object'>)
11. (<class '__main__.C0'>, <class '__main__.C2'>, <class '__main__.C3'>, <class '__main__.C4'>, <class '__main__.C5'>, <class '__main__.C6'>, <class '__main__.C7'>, <type 'object'>)

0