import os
#获取当前路径
print os.path.dirname(os.path.abspath(__file__))
<pre name="code" class="python">#获取当前路径
print os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
#获取上级目录
print os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
<pre name="code" class="python">#获取当前路径
print os.getcwd()
<pre name="code" class="python">#获取上级目录
print os.path.dirname(os.getcwd())