0

I need to add my program's outputs to a saved file every time I run the program without overwriting the previous outputs.

This is how I'm writing to a file now:

lead.write(str(alldates))

Any ideas?

  • 1
    Maybe you should spend some time looking at the documentation for the most basic methods you might be using, such as [`open`](http://docs.python.org/2.7/library/functions.html#open). – metatoaster Mar 13 '14 at 07:16
  • 1
    possible dup - http://stackoverflow.com/questions/4706499/how-do-you-append-to-file-in-python – santosh-patil Mar 13 '14 at 07:17

2 Answers2

2

Here, you should open the file in append mode:

append_text = str(alldates)
with open('my_file.txt', 'a') as lead:
    lead.write(append_text)

There are lots of specialised ways to open files for different purposes, and you can read about them in the documentation.

anon582847382
  • 19,907
  • 5
  • 54
  • 57
0

You should open the file in append mode.

satoru
  • 31,822
  • 31
  • 91
  • 141