I'm working on a simple python script to write some data to two text files. My code looks like this:
with open('file1.txt', 'w') as file1:
for thing in stuff1:
file1.write(thing + '\n')
with open('file2.txt', 'w') as file2:
for thing in stuff2:
file2.write(thing + '\n')
When I run the program, file1 turns out as expected, but file2 is empty.
However, if I switch the order in which I write to the files (meaning I write to file2 first and then to file1), file2 turns out as expected and file1 is empty.
In other words, the file to which I write second always turns out empty.
I tried adding file1.flush() / file2.flush() inside of the loops, but to no avail. Any idea why this could be happening?