报错提示:
with open(results_file,"a+") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'results/result_20240402-001500.txt'
当前目录下没有results文件夹,open(results_file,"a+")只会自动创建文件,不会自动创建文件夹,所以报错。
import datetime
import os
import sys
results_file = "results/result_{}.txt".format(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
#results_file="results/result_.txt"
print(os.getcwd())
with open(results_file,"a+") as f:
print('vvv')
在当前目录下新建好results文件夹即可