HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonCriticalCanonical

How do I append to a file?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
appendhowfile

Problem

How do I append to a file instead of overwriting it?

Solution

Set the mode in open() to "a" (append) instead of "w" (write):
with open("test.txt", "a") as myfile:
myfile.write("appended text")


The documentation lists all the available modes.

Context

Stack Overflow Q#4706499, score: 3175

Revisions (0)

No revisions yet.