擅长:python、mysql、java
<p>通常,要导入模块,我们不需要使用搜索路径公司名称:</p>
<p><strong>主.py</strong></p>
<pre><code>from a import a
# first 'a' is the directory. second 'a' is a.py
# the 'a' directory needs to have __init__.py which can be blank
from b import b
</code></pre>
<p><strong>a/a.py</strong></p>
^{pr2}$
<p><strong>b/b.py</strong></p>
^{pr2}$
<p>由于无法修改外部模块,因此可以在导入时重命名具有相同名称的模块:</p>
<p><strong>主.py</strong></p>
<pre><code>from a import utils as utils_a
from b import utils as utils_b
utils_a.hello()
utils_b.hello()
</code></pre>