Niranjan S. answered 04/01/19
Experienced Tutor Specializing in Python
You should use 'a+' which appends the file. And '\n' for a new line.
Niranjan S. answered 04/01/19
Experienced Tutor Specializing in Python
You should use 'a+' which appends the file. And '\n' for a new line.
CF S. answered 03/29/19
Python Programming and Machine Learning Tutor in Fairfax
https://www.guru99.com/reading-and-writing-files-in-python.html
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Harly B.
When you open with "a" mode , the write position will always be at the end of the file (an append). There are other permutations of the mode argument for updating (+), truncating (w) and binary (b) mode but starting with just "a" is your best. If you want to seek through the file to find the place where you should insert the line, use 'r+'. You can also use file access_mode "a+" for Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file . The initial file position for reading is at the beginning of the file, but output is appended to the end of the file. with open("index.txt", "a+") as myfile: myfile.write("New text appended") http://net-informations.com/python/iq/append.htm06/10/20