1、a.py文件存放的路徑下為(D:\Auto\eclipse\workspace\Testhtml\Test)
2、通過os.getcwd()獲取的路徑為:D:\Auto\eclipse\workspace\Testhtml\Test
3、使用os.getcwd()[:-4]截取到的路徑為:D:\Auto\eclipse\workspace\Testhtml\
4、使用下面的命令則在3步驟下新建report文件夾,並將執行的結果會自動保存在report文件夾下
import os
File_Path = os.getcwd()[:-4] +'report\\' #獲取到當前文件的目錄,並檢查是否有report文件夾,如果不存在則自動新建report文件 if not os.path.exists(File_Path): os.makedirs(File_Path)