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
Published on 22-Dec-2017 10:49:21
Advertisements