擅长:python、mysql、java
<pre><code>import sys, os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'library')))
import utils
</code></pre>
<p>这将修改sys.path变量,该变量包含要搜索文件的目录。它还将确保它能够正确地找到它,即使您将其运行为:</p>
<pre><code>$ python the_file.py
$ python ../the_file.py
$ python /somewhere/over/the_file.py
</code></pre>
<p>这将适用于正在开发、测试、培训的东西。安装的文件不需要这样的构造。</p>