<blockquote>
<p><strong>Duplicate:</strong><br/>
<a href="https://stackoverflow.com/questions/50499/in-python-how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executin">In Python, how do I get the path and name of the file that is currently executing?</a></p>
</blockquote>
<p>如何获取正在运行的Python脚本的路径?我在做<code>dirname(sys.argv[0])</code>,但是在Mac上我只得到文件名,而不是像在Windows上那样得到完整的路径。</p>
<p>无论应用程序从何处启动,我都希望打开与脚本文件相关的文件。</p>