How to open a file in append mode with Python?

PythonServer Side ProgrammingProgramming

To open files in append mode, specify 'a' as the mode(a=append). For example,

f = open('my_file.txt', 'a')
file_content = f.read()
f.write('Hello World')
f.close()

Above code opens my_file.txt in append mode and appends the file to contain "Hello World" at the end.

raja
Updated on 01-Oct-2019 11:48:33

Advertisements