脚本文件本地目录挂入系统环境变量
import sys, os
sys.path.append(os.pardir)
print(sys.path)
os.getcwd()获取当前目录路径
import os
current_path = os.getcwd() # 获取当前工作目录的路径
print(current_path)
print("1:"+ os.path.join('aaaa','/bbbb','ccccc.txt'))
print("2:"+ os.path.join('/aaaa','/bbbb','/ccccc.txt'))
print("3:"+ os.path.join('aaaa','./bbb','ccccc.txt'))
但由于vscode运行 os.getcwd()定位是在workspace和终端运行的结果会有区别(少一层),这点需要注意
import os
# os.getcwd()
data_path = os.path.join(os.getcwd(),"test/data")
print(data_path)
vscode与终端区别