Every time you enter and exit the with open... block, you're reopening the file. As the other answers mention, you're overwriting the file each time. In addition to switching to an append, it's probably a good idea to swap your with and for loops so you're only opening the file once for each set of writes:
with open("output.txt", "a") as f:
for key in atts:
f.write(key)
Answer from glibdud on Stack OverflowWriting to file using Python - Stack Overflow
How does one read and write to files in python?
Writing a for loop to a excel file
You could use a comma separated value to store the table.
More on reddit.com[Python] How do you write a non string to a file?
Videos
Every time you enter and exit the with open... block, you're reopening the file. As the other answers mention, you're overwriting the file each time. In addition to switching to an append, it's probably a good idea to swap your with and for loops so you're only opening the file once for each set of writes:
with open("output.txt", "a") as f:
for key in atts:
f.write(key)
You need to change the second flag when opening the file:
wfor only writing (an existing file with the same name will be erased)aopens the file for appending
Your code then should be:
with open("output.txt", "a") as f:
I have watched many a YouTube video, but alas, it just confused me more. What is the python equivalent to things like File.WriteLine in c#?
Thanks in advance.