擅长:python、mysql、java
<p>将ASDF1(父类之一)作为第一个参数传递给super()。别那么做。相反,您应该将ASDF作为第一个参数传递给super()。</p>
<p><a href="https://docs.python.org/2/library/functions.html#super" rel="nofollow">Python 2.7 documentation for super()</a></p>
<p>引用Python2.7文档,典型的超类调用如下所示:</p>
<pre><code>class C(B):
def method(self, arg):
super(C, self).method(arg)
</code></pre>
<p>注意这里super的第一个参数是C,它是当前类。不要将B(父类)传递给super()。</p>
<p>在确定方法解析顺序(MRO)时,超级跳过作为其第一个参数传入的类,并开始查看该类的父类和兄弟类。因此,当您将ASDF1作为第一个参数传递给super()时,它跳过ASDF1并使用ASDF2开始搜索。这就是为什么ASDF2的<code>__init__</code>被调用的原因。</p>
<hr/>
<p>在Python3中,您不必再传递当前类。</p>
<pre><code>class C(B):
def method(self, arg):
super().method(arg) # This does the same thing as:
# super(C, self).method(arg)
# (Python 3 only)
</code></pre>