Python中多重继承的初始化

问题描述 投票:0回答:2

我遇到了以下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的对象的过程是什么?

python class multiple-inheritance
2个回答
2
投票

在呼叫EClient.__init__(self, self)中,第一个self变为EClientEClient中的def __init__(self, wrapper):。接下来,您可能会看到,第二个self被绑定到该调用中的wrapperTestApp继承了EWrapper,因此将其用作wrapperEClient


1
投票

初始化TestApp时,先使用selfEWrapper,然后使用EClient,因为这是该类中定义的顺序。

© www.soinside.com 2019 - 2024. All rights reserved.