import os
print('------获取当前--------')
print(os.getcwd())
print(os.path.abspath(os.path.dirname(__file__)))
print('-------获取上级---------')
print(os.path.abspath(os.path.dirname(os.getcwd())))
print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
print(os.path.abspath(os.path.join(os.getcwd(), "..")))
print('-----获取上上级------')
print(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
print(os.path.abspath(os.path.join(os.getcwd(), "..\..")))
python文件路径的几种写法
最新推荐文章于 2024-08-27 21:53:24 发布