python3将print中的输出内容保存至txt文件

Posted 鸿渐之翼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3将print中的输出内容保存至txt文件相关的知识,希望对你有一定的参考价值。

我们的目标是将print输出导入txt,实现方法如下:

log = open("a.txt",mode="a",encoding="utf-8")
for i in range(100):
    a=b()
    print(a,file = log)
log.close()

以上是关于python3将print中的输出内容保存至txt文件的主要内容,如果未能解决你的问题,请参考以下文章