import os
base_dir = os.path.dirname(__file__)
# 获取当前文件目录
path = os.path.join(base_dir,'123.txt')
# 获取文件拼接后的路径
转自https://blog.csdn.net/qq_42034590/article/details/80031241 @吃肉的小馒头