I already created a txt file using python with a few lines of text that will be read by a simple program. However, I am having some trouble reopening the file and writing ad
Open the file for 'append' rather than 'write'.
with open('file.txt', 'a') as file:
file.write('input')
Use 'a', 'a' means append. Anything written to a file opened with 'a' attribute is written at the end of the file.
with open('file.txt', 'a') as file:
file.write('input')
If you want to append to the file, open it with 'a'. If you want to seek through the file to find the place where you should insert the line, use 'r+'. (docs)