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 sum()
Python slice()
Python Program to Illustrate Different Set Operations
Python Program to Get Line Count of a File
How to get current date and time in Python?
Python Program to Check the File Size
Python Function Arguments
Python Program to Print the Fibonacci sequence
Python dir()
Python Program to Count the Occurrence of an Item in a List
Python Package
Python String find()
Python String expandtabs()
Python Program to Represent enum
Python String rpartition()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python id()
Python Program to Find the Largest Among Three Numbers
Python Program to Count the Number of Digits Present In a Number
Python Machine Learning - Sebastian Raschka
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python reversed()
Python Program to Multiply Two Matrices
Python String ljust()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Set remove()
Python Input, Output and Import
Python String startswith()
Python List insert()
Python Dictionary pop()