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


 1 import os
 2 
 3 print '***获取当前目录***'
 4 print os.getcwd()
 5 print os.path.abspath(os.path.dirname(__file__))
 6 
 7 print '***获取上级目录***'
 8 print os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 9 print os.path.abspath(os.path.dirname(os.getcwd()))
10 print os.path.abspath(os.path.join(os.getcwd(), ".."))
11 
12 print '***获取上上级目录***'
13 print os.path.abspath(os.path.join(os.getcwd(), "../.."))

 


免责声明!

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



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