【问题标题】:File new line writing文件换行写入
【发布时间】:2020-07-15 22:09:20
【问题描述】:
from re import findall
output = 0

f = open("100$ School.txt", "w+")

f.write(str(output))

我的目标是让它每次运行时都会在新行中写入。 感谢任何花时间来遮阳篷的人

【问题讨论】:

  • 你的问题是什么?

标签: python python-3.x file file-io


【解决方案1】:

你可以试试这个。

with open("100$ School.txt", "w+") as f:
    f.write(str(output)+"\n")

【讨论】:

    【解决方案2】:

    您需要附加它才能不被覆盖。所以w+ 必须是a+

    from re import findall
    output = 0
    
    f = open("100$ School.txt", "a+")
    
    f.write(str(output)+"\n")
    

    【讨论】:

      【解决方案3】:

      试试这个:

      f = open("100$ School.txt", "a+") # "a+" for append
      f.write(f"{output}\n")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-02
        • 2012-01-19
        • 1970-01-01
        • 1970-01-01
        • 2011-03-05
        • 1970-01-01
        • 2020-10-06
        相关资源
        最近更新 更多