How do you append to a file?

This can be achieved by setting the mode in open() to "a" (append) instead of "w" (write). See the documentation op open() for all available modes.

with open("test.txt", "a") as myfile:
    myfile.write("appended text")

Leave a Comment