擅长:python、mysql、java
<p><code>__import__</code>的工作方式与<code>import</code>语句相同。(有充分的理由)</p>
<p>执行此操作时:</p>
<pre><code>import foo.bar.baz
</code></pre>
<p>你的文件中没有<code>baz</code>对象;你得到了<code>foo</code>!同样,这:</p>
^{pr2}$
<p>返回<code>foo</code>模块,但要保证它是用<code>bar</code>填充的。在</p>
<p>因此在您的示例中,<code>__import__</code>返回{<cd8>},您必须自己遍历路径的其余部分。这很糟糕,这就是<code>importlib</code>有用的原因。:)</p>