引入包:
import os
正確獲取當前的路徑:
__file__是當前執行的文件
#當前文件路徑 print(os.path.realpath(__file__)) #當前文件所在的目錄,即父路徑 print(os.path.split(os.path.realpath(__file__))[0]) #找到父路徑下的其他文件,即同級的其他文件 print(os.path.join(proDir,"config.ini"))
引入包:
import os
正確獲取當前的路徑:
__file__是當前執行的文件
#當前文件路徑 print(os.path.realpath(__file__)) #當前文件所在的目錄,即父路徑 print(os.path.split(os.path.realpath(__file__))[0]) #找到父路徑下的其他文件,即同級的其他文件 print(os.path.join(proDir,"config.ini"))
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。