<p>“超级”是一个内置的。除非您特意删除了内置项,否则您永远不会看到“global name‘super’is not defined”。在</p>
<p>我在看你的<a href="http://logdiones.blogspot.com/" rel="noreferrer">user web link</a>,那里有一堆自省助手。如果没有缩进,很难阅读,但看起来你可能正是这样做的:</p>
<pre><code>built_in_list = ['__builtins__', '__doc__', '__file__', '__name__']
for i in built_in_list:
if i in module.__dict__:
del module.__dict__[i]
</code></pre>
<p>这是您要更改的原始模块dict,而不是您要返回的信息副本!从一个活动模块中删除这些成员,你就可以期待更多的“超级”破坏。在</p>
<p>很难跟踪那个模块在做什么,但我的反应是其中有太多的魔力。一般的Python程序不应该在导入系统上乱搞,搜索路径和猴子修补魔术模块成员。一点点魔法可以是一个巧妙的把戏,但这是极其脆弱的。在我浏览它的时候,代码可能会被如下内容破坏:</p>
<ul>
<li>名称与顶级模块冲突</li>
<li>是否使用新样式的类</li>
<li>仅作为编译字节码提供的模块</li>
<li>zipimporter公司</li>
</ul>
<p>从getClassDefinitions、ExtractModuleName和isFromBase等函数开始,在我看来,您仍有相当多的内容需要了解Python的基本原理。(线索:getattr、module.\uu name_uu和issubclass)</p>
<p>在这种情况下,现在是<em>而不是</em>潜入进口魔法的时候了!这很难。相反,用普通的Python方法来做。在一个包的mypackage/\uu init_uu.py的底部,可能需要输入更多的内容:</p>
^{pr2}$
<p>但它将在任何地方发挥作用并被理解,而不需要依赖于一堆复杂而脆弱的魔法。在</p>
<p>顺便说一句,除非您计划进行一些深入的多重继承工作(再说一次,现在可能不是进行此工作的时候),否则您可能根本不需要使用super()。调用已知超类的通常的“IPlugin.\uu init_uu(self,…)”方法是很简单的;super()并不总是“更新、更好的方法”和<a href="http://fuhm.net/super-harmful/" rel="noreferrer">there are things you should understand about it</a>,然后再开始使用它。在</p>