Python 文件新行写入
我的目标是让它在每次运行时都写在新行中。 感谢所有花时间观看awnser的人,您可以试试这个Python 文件新行写入,python,python-3.x,file,file-io,Python,Python 3.x,File,File Io,我的目标是让它在每次运行时都写在新行中。 感谢所有花时间观看awnser的人,您可以试试这个 from re import findall output = 0 f = open("100$ School.txt", "w+") f.write(str(output)) 您需要追加以使其不被覆盖。所以w+需要是a+ 从重新导入findall 输出=0 f=开放(“100$School.txt”,“a+”) f、 写入(str(输出)+“\n”) 试试这个: with open("100$
from re import findall
output = 0
f = open("100$ School.txt", "w+")
f.write(str(output))
您需要追加以使其不被覆盖。所以
w+
需要是a+
从重新导入findall
输出=0
f=开放(“100$School.txt”,“a+”)
f、 写入(str(输出)+“\n”)
试试这个:
with open("100$ School.txt", "w+") as f:
f.write(str(output)+"\n")
你的问题是什么?
f = open("100$ School.txt", "a+") # "a+" for append
f.write(f"{output}\n")