代码:
current_dir = os.getcwd()
print(current_dir)
print(os.path.abspath(os.path.dirname(os.getcwd())))
print(os.path.abspath(os.path.dirname(__file__)))
打印:
PS D:\VOS_RedRock_TC397_1_old> & C:/Python38/python.exe d:/VOS_RedRock_TC397_1_old/Tools/AutoScripts/main.py
D:\VOS_RedRock_TC397_1_old
D:\
d:\VOS_RedRock_TC397_1_old\Tools\AutoScripts
由此看出:
当前文件路径用 os.path.abspath(os.path.dirname(__file__))
当前工作路径用 os.path.abspath(os.path.dirname(os.getcwd()))
返回当前工作目录用os.getcwd()