Skip to content Skip to sidebar Skip to footer

Write To The Last Line Of A Text File?

I am trying to get the program to automatically start at the last line of a text file when I run it and make it write on the last line. My current code is as follows: with open('te

Solution 1:

Use the a flag while opening the file

with open('path/to/file', 'a') as outfile:
    outfile.write("This is the new last line\n")

Post a Comment for "Write To The Last Line Of A Text File?"