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 Objects and Classes
Python setattr()
Python ascii()
Python Statement, Indentation and Comments
Python Program to Safely Create a Nested Directory
Python getattr()
Python slice()
Python Dictionary update()
Python String index()
Python Program to Convert Two Lists Into a Dictionary
Python iter()
Python Set pop()
Python String replace()
Python List sort()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Set union()
Python Program to Swap Two Variables
Python Set clear()
Python Program to Represent enum
Python List copy()
Python id()
Python Program to Multiply Two Matrices
Python Program to Find LCM
Python sum()
Python Program to Count the Number of Digits Present In a Number
Python Set intersection_update()
Debug a JavaMail Program
Python String isidentifier()
Python __import__()
Python Program to Sort a Dictionary by Value
Python time Module
Python Program to Print Colored Text to the Terminal