python 获取当前目录和上级目录

来源:互联网 发布:安卓跑分软件 编辑:程序博客网 时间:2024/05/16 09:25
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())

0 0
原创粉丝点击