File new line writing

Viewed 59
from re import findall
output = 0

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

f.write(str(output))

My goal is to have it so every time it runs it writes it in a new line. Thank you to anyone who takes to the time to awnser

3 Answers

You need to append for it to not overwrite. so w+ needs to be a+

from re import findall
output = 0

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

f.write(str(output)+"\n")

You can try this.

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

Try this one:

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