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 Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python abs()
Python List index()
Python String rfind()
Python Dictionary setdefault()
Python Errors and Built-in Exceptions
Python divmod()
Python Program to Extract Extension From the File Name
Python Data Types
Python Program to Remove Punctuations From a String
Python Program to Compute all the Permutation of the String
Python Program to Find HCF or GCD
Python Decorators
Python String casefold()
Python Strings
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Convert Bytes to a String
Python List insert()
Python Program to Check the File Size
Python Recursion
Python eval()
Python List extend()
Python help()
Python Program Read a File Line by Line Into a List
Python String isupper()
Python Program to Find Factorial of Number Using Recursion
Python Program to Find the Square Root
Python Directory and Files Management
Python open()
Python Set union()
Python String rsplit()
Python Program to Reverse a Number