擅长:python、mysql、java
<p>使用<code>sys.path[0]</code>可以得到较短的版本。</p>
<pre><code>os.chdir(sys.path[0])
</code></pre>
<p>来自<a href="http://docs.python.org/library/sys.html#sys.path" rel="noreferrer">http://docs.python.org/library/sys.html#sys.path</a></p>
<blockquote>
<p>As initialized upon program startup, the first item of this list,
<code>path[0]</code>, is the directory containing the script that was used to
invoke the Python interpreter</p>
</blockquote>