目录
如下图所示,欲将下图内容写入一个.txt

使用f.write()函数, 如果记事本想要换行,需要换行符"\n"
- write_file = "/home/qtxu/test/test2.txt"
- with open(write_file, "a") as f:
- f.write("========================================"+"\n")
- f.write("fold: {} Best Model Measure".format(0)+"\n")
- f.write("========================================")
解锁新写法, file=f, 无须换行符,会自动换行
- write_file = "/home/qtxu/test/test.txt"
- with open(write_file, "a") as f:
- print("========================================", file=f)
- print("fold: {} Best Model Measure".format(0), file=f)
- print("========================================", file=f)