简体   繁体   English

python inheritance:__init__(自我,自我)?

[英]python inheritance: __init__ (self, self)?

I see a piece of code that is我看到一段代码是

class IBapi(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)

I'm confused what the self, self does.我很困惑self, self做了什么。 I'm used to something like this.我已经习惯了这样的事情。

class TestClient(EClient):
    def __init__(self, wrapper):
        EClient.__init__(self, wrapper)

Can someone explain self, self ?有人可以解释一下self, self吗?

self is an object of the class "IBapi" and also an instance of the classes "EWrapper" and "EClient" through inheritance. self 是 class "IBapi" 的 object 以及 inheritance 类 "EWrapper" 和 "EClient" 的实例。 I am guessing that the constructor of "EClient" gets an instance of "EWrapper" as a parameter.我猜“EClient”的构造函数获取“EWrapper”的一个实例作为参数。 You can think of your code like this:你可以这样想你的代码:

class IBapi(EWrapper, EClient):
  def __init__(self):
    wrapper = self
    EClient.__init__(self, wrapper)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM