Writing to Files in Python


Write data to files, overwriting or appending.

Source Code

with open("output.txt", "w") as file:  # Overwrites the file
    file.write("New contentn")

with open("output.txt", "a") as file:  # Appends to the file
    file.write("Additional contentn")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments