How do I write from the back of the file?

Asked 2 years ago, Updated 2 years ago, 119 views

I don't want to overwrite the file but I want to add it to the back, but I can't find a way Who wants to teach me?

file python append

2022-09-22 15:46

1 Answers

Write open(fildname, "a") The second factor in open is related to the mode of reading and writing files.

The difference between r+ and a+ is in current look position. If you open it with r+ and write it right away, write it from the front of the file If you open it with a+ and write it right away, write it from the back of the file.

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


2022-09-22 15:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.