我遇到了以下python代码,其中一个类继承自两个父类。我试图理解这个类的构造函数
# wrapper.py:
#############
class EWrapper:
def __init__(self):
pass
...
# client.py
###########
class EClient(object):
def __init__(self, wrapper):
self.msg_queue = queue.Queue()
self.wrapper = wrapper
self.decoder = None
self.reset()
....
# Test.py
#########
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
有没有人能对EClient.__init__(self, self)
多解释一下?我不清楚两个self
的用法。python如何知道哪个self
是哪个
构建TestApp
对象的过程是什么
在调用
EClient.__init__(self, self)
中,第一个self
变为EClient
中的EClient
的def __init__(self, wrapper):
。接下来,如您所见,第二个self
在该调用中绑定到wrapper
TestApp
继承EWrapper
,因此它将自身用作EClient
的wrapper
初始化
TestApp
时,您使用的是EWrapper
的self
,然后是EClient
,因为这是类中定义的顺序相关问题 更多 >
编程相关推荐