擅长:python、mysql、java
<h2><strong>从Python 3.4更新</h2>
<p>使用<code>pathlib</code>模块。</p>
<pre><code>from pathlib import Path
path = Path("/here/your/path/file.txt")
print(path.parent)
</code></pre>
<h2><strong>旧答案</strong></h2>
<p>试试这个:</p>
<pre><code>import os.path
print os.path.abspath(os.path.join(yourpath, os.pardir))
</code></pre>
<p>其中<code>yourpath</code>是要父级的路径。</p>