Additional content to file

If you add content to give the file instead of overwriting existing content, you can append mode opens the file. You append mode
when you open the file, Python will not clear the file before returning file object, and you write to a file rows are added to the end of the file.
If the specified file does not exist, Python will you create an empty file.

filename = 'programming1.txt'
with open(filename, 'a') as file_object:
#with open(filename, 'w') as file_object:
    file_object.write("I also love finding meaning in large datasets.\n")
    file_object.write("I love creating apps that can run in a browser.\n")
Published 145 original articles · won praise 6 · views 8059

Guess you like

Origin blog.csdn.net/sinat_23971513/article/details/105054091