码迷,mamicode.com
首页 > 编程语言 > 详细

关于 python 新式类和旧式类继承顺序的验证

时间:2017-09-05 10:49:10      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:tle   order   actual   limit   blog   app   sequence   eth   log   

参考:http://www.cnblogs.com/blackmatrix/p/5630515.html

官方:https://docs.python.org/2/tutorial/classes.html 

 

 

关于多继承问题

 

Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks like this:

For old-style classes, the only rule is depth-first, left-to-right. Thus, if an attribute is not found in DerivedClassName, it is searched in Base1, then (recursively) in the base classes of Base1, and only if it is not found there, it is searched in Base2, and so on.

(To some people breadth first — searching Base2 and Base3 before the base classes of Base1 — looks more natural. However, this would require you to know whether a particular attribute of Base1 is actually defined in Base1 or in one of its base classes before you can figure out the consequences of a name conflict with an attribute of Base2. The depth-first rule makes no differences between direct and inherited attributes of Base1.)

For new-style classes, the method resolution order changes dynamically to support cooperative calls to super(). This approach is known in some other multiple-inheritance languages as call-next-method and is more powerful than the super call found in single-inheritance languages.

 

 

试验部分

 

请看这里

 

 

以上.

关于 python 新式类和旧式类继承顺序的验证

标签:tle   order   actual   limit   blog   app   sequence   eth   log   

原文地址:http://www.cnblogs.com/tiantiandas/p/python_class_inherit_order.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!