In this example, you will learn to append to a file.
To understand this example, you should have the knowledge of the following Python programming topics:
Open file in append mode and write to it
The content of the file my_file.txt is
honda 1948 mercedes 1926 ford 1903
The source code to write to a file in append mode is:
with open("my_file.txt", "a") as f:
f.write("new text")
The content of the file after appending a text to it is:
honda 1948 mercedes 1926 ford 1903new text
Open the file in append 'a' mode, and write to it using write() method. Inside write() method, a string "new text" is passed. This text is seen on the file as shown above.
If you want to learn more about different types of file opening modes, please refer to Python file I/O.
Related posts:
Python callable()
Python List Comprehension
Python filter()
Python Matrices and NumPy Arrays
Python Program to Get the Class Name of an Instance
Python property()
Python Set copy()
Python oct()
Python hash()
Python Program to Get the File Name From the File Path
Python Program to Display the multiplication Table
Python Recursion
Python Program to Add Two Numbers
Python Program to Merge Mails
Deep Learning with Python - Francois Chollet
Python Program to Generate a Random Number
Python open()
Python vars()
Python Set union()
Python Dictionary values()
Python print()
Python Set remove()
Python Program to Concatenate Two Lists
Python List append()
Python List insert()
Python sorted()
Python List clear()
Python pow()
Python Set isdisjoint()
Python sleep()
Python Program to Measure the Elapsed Time in Python
Python String casefold()