python 获取上级(上上级目录..)


import os
import sys print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__))
print '***获取上级目录***' print os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
sys.path.append(...)
print os.path.abspath(os.path.dirname(os.getcwd()))
os.path.abspath(os.path.dirname(os.getcwd()))
sys.path.append(...)
print os.path.abspath(os.path.join(os.getcwd(), ".."))
os.path.abspath(os.path.join(os.getcwd(), ".."))
sys.path.append(print os.path.abspath(os.path.join(os.getcwd(), "..")))

print '***获取上上级目录***'
print os.path.abspath(os.path.join(os.getcwd(), "../.."))
os.path.abspath(os.path.join(os.getcwd(), "../.."))
sys.path.append(os.path.abspath(os.path.join(os.getcwd(), "../..")))

转载:https://www.cnblogs.com/yang220/p/13597518.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM