Forums

print() to .txt file not working?

I am trying to just do a simple

out = open('output.txt')
print('concatenated verbage', file=out)
out.close()

but after the print() block has been run, the output file is blank. I have confirmed that the block runs by taking out the ", file=out" portion of the call.

Is there an extra step necessary to make this work?

Alright, I think it's just delayed. I don't know how long it takes to update the file itself, but after I waited a half hour, everything I was printing appeared.

See our help page about making sure that you're writing to or reading from the file you expect: https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/