How does python add content to the document continuously instead of overwriting the original content when calling the program

When we use python to write files into documents, we usually encounter such a situation, that is, every time the same program is called, the new data written will overwrite the contents of the original document in the document. How to do not overwrite the original document content, that is, when we use various write document functions, we will use the

with open("spider.txt", "w") as f:

or

csvfile = open('test.csv', 'w', newline='')

and so on. Note that both of these two open documents use the "w" form to open the document, we will replace it with "a" to open the document, that is

with open("spider.txt", "a") as f:
csvfile = open('test.csv', 'a', newline='')

In this way, the last document written in the document will not overwrite the original content.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324576592&siteId=291194637