0

When I open a text file and write in it and at the end of the program close it, the lines stay in the text file. When i reopen that program, rather than writing on a new set of lines, it overwrites what is already there. I want to keep both pieces of text, it is for data logging. Any ideas on how to fix this.

Lachlan.C
  • 1
  • 1
  • Open the file in append mode. See: http://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file-in-python – anujm May 28 '16 at 11:25

1 Answers1

1

You should use the a mode, like this:

with open("file","a") as f:
    f.write("Something") 

This will append to the file instead of overwriting it.

noteness
  • 2,440
  • 1
  • 15
  • 15