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 Program to Find the Factorial of a Number
Python Type Conversion and Type Casting
Python Closures
Python time Module
Python iter()
Python Program to Print Output Without a Newline
Python tuple()
Python Program to Check Leap Year
Python Dictionary items()
Python Set union()
Python Program to Check If Two Strings are Anagram
Python String zfill()
Python id()
Python Program to Find ASCII Value of Character
Python Program to Iterate Through Two Lists in Parallel
Python List index()
Python map()
Python format()
Python Program to Find LCM
Python Program to Remove Punctuations From a String
Python property()
Python Program to Transpose a Matrix
Python Program to Get the File Name From the File Path
Python locals()
Python String rsplit()
Python list()
Python Program to Measure the Elapsed Time in Python
Python Set difference_update()
Python Data Structures and Algorithms - Benjamin Baka
Python Matrices and NumPy Arrays
Python List Comprehension
Python Dictionary get()