Forums

Write to a txt file in pythonanywhere?

Hello i'm a beginner in pythonanywhere.

I'm trying to write to a txt file but it isn't working, this is my code:

write_file = open("/home/Debonnet/test/test.txt", "a")
write_file.write("test2")
write_file.close

But nothing is being written to the file..I tried "w" instead of "a" also but nothing changes..

Close is a method. You need to call it like this write_file.close()