在项目执行的过程中,一般会先从程序入口执行,这样使用os.os.path.abspath(file) 获得的是执行文件的全路径,我们可以使用os.path.dirname(os.path.abspath(file)) 获得执行文件的上级路径,再根据上级路径去取log、report等文件的路径。
#获得当前的文件路径
os.getcwd()
'E:\\workspace\\PythonTest\\itgApp_test'
#获得当前文件路径的绝对路径
os.path.abspath(os.getcwd())
'E:\\workspace\\PythonTest\\itgApp_test'
#获得当前文件的上级路径