1、a.py文件存放的路径下为(D:AutoeclipseworkspaceTesthtmlTest)
2、通过os.getcwd()获取的路径为:D:AutoeclipseworkspaceTesthtmlTest
3、使用os.getcwd()[:-4]截取到的路径为:D:AutoeclipseworkspaceTesthtml
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)