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 delattr()
Python Program to Find Factorial of Number Using Recursion
Python Program to Parse a String to a Float or Int
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python int()
Python dir()
Python String isalnum()
Python Program to Find the Square Root
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Type Conversion and Type Casting
Python @property decorator
Python tuple()
Python Program to Multiply Two Matrices
Python Program to Find ASCII Value of Character
Python Program to Count the Number of Each Vowel
Python Set issuperset()
Python Program to Convert Kilometers to Miles
Python eval()
Python time Module
Python List extend()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Remove Duplicate Element From a List
Python String ljust()
Python Program to Differentiate Between type() and isinstance()
Python break and continue
Python filter()
Python Program to Concatenate Two Lists
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
How to get current date and time in Python?
Python Dictionary get()
Python Program to Make a Flattened List from Nested List
Python Program to Delete an Element From a Dictionary