python常用

1、python獲取當前文件路徑以及父文件路徑

#當前文件的路徑
pwd = os.getcwd()
#當前文件的父路徑
father_path=os.path.abspath(os.path.dirname(pwd)+os.path.sep+".")
#當前文件的前兩級目錄
grader_father=os.path.abspath(os.path.dirname(pwd)+os.path.sep+"..")

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章