Python: Saving A String To File Without Overwriting File's Contents
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(alld
Solution 1:
Here, you should open
the file in a
ppend mode:
append_text = str(alldates)
withopen('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.
Post a Comment for "Python: Saving A String To File Without Overwriting File's Contents"