Inactive Tutor answered 04/01/19
Tutor
New to Wyzant
f = open(fileName, 'a+')
f.write("something" + '\n')
You should use 'a+' which appends the file. And '\n' for a new line.
Inactive Tutor answered 04/01/19
You should use 'a+' which appends the file. And '\n' for a new line.
Inactive Tutor answered 03/29/19
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