python 多继承(2)
from: http://www.chinesepython.org/pythonfoundry/tut2.3/tmp/multiple.html
9.5.1 多继承 Multiple Inheritance
Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks as follows:
Python同样有限的支持多继承形式。多继承的类定义形如下例:
class DerivedClassName(Base1, Base2, Base3):
<statement-1>
.
.
.
<statement-N>
The only rule necessary to explain the semantics is the resolution rule used for class attribute references. This 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.
这里唯一需要解释的语义是解析类属性的规则。顺序是深度优先,从左到右。因此,如果在 DerivedClassName (示例中的派生类)中没有找到某个属性,就会搜索 Base1 ,然后(递归的)搜索其基类,如果最终没有找到,就搜索 Base2,以此类推。
(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.)
(有些人认为广度优先--在搜索Base1的基类之前搜索Base2和Base3--看起来更为自然。然而,如果Base1和Base2之间发生了命名冲突,你需要了解这个属性是定义于Base1还是Base1的基类中。而深度优先不区分属性继承自基类还是直接定义。)
It is clear that indiscriminate use of multiple inheritance is a maintenance nightmare, given the reliance in Python on conventions to avoid accidental name conflicts. A well-known problem with multiple inheritance is a class derived from two classes that happen to have a common base class. While it is easy enough to figure out what happens i
相关文档:
转载自
http://blog.163.com/skynjl/blog/static/603053922009127101558356/
今天同事叫我编写一个shell脚本。话说,虽然我受*nix的影响甚深,但是对于*nix 里随处可见的sh脚本却是讨厌之极。为什么讨厌呢?首先是因为sh脚本那莫名其妙的语法,感觉就像随写随扔的程序,完全没有任何美感可言。其次是sh脚 ......
Python
的
C/C++
扩展
By phidoit@gmail.com
可扩展性是
Python
的一大特色,一方面,由于
Python
是解释执行的,这导致运行速 ......
这是我以前写的一个socket小应用,其中也顺便用到了一点点多线程的东西。
这个socket客户端是我为了方便公司的充值系统调试而写的一个小应用。由它跟充值系统进行socket通讯,自动完成充值的测试工作。
看代码吧:
import socket,thread
def Communicate(s):
phoneno = raw_input("Please input your PhoneNo.:(Pu ......
我们在做软件开发的时候很多要用到多线程技术。例如如果做一个下载软件象flashget就要用到、象在线视频工具realplayer也要用到因为要同时下载media stream还要播放。其实例子是很多的。
线程相对进程来说是“轻量级”的,操作系统用较少的资源创建和管理线程。程序中的线程在相同的内存空间中执行,并共享许多相 ......