Python Principles
Python Q&A

How can I append to a file?


Open the file in append mode by passing the a flag to the open function. Here is an example:

with open("file.txt", "a") as f:
    f.write("This gets appended.")

Or alternatively, avoiding the with keyword:

f = open("file.txt", "a")
f.write("Just appending stuff")