0
点赞
收藏
分享

微信扫一扫

python保存运行结果到txt

前行的跋涉者 2022-03-30 阅读 72
python

python跑程序结束要记得保存结果哦


import time
now = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())#文件名字不能有:
now1 = str(now) + "train.txt"#前面加上时间防止重复
fh = open(now1, 'w', encoding='utf-8')

for i in range(1):
    fh.write(str(ls))#ls是我要保存的list,只能转化为str
    fh.write('\n')
fh.close()
举报

相关推荐

0 条评论