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 globals()
Python Set issuperset()
Python oct()
Python List extend()
Python String casefold()
Python Object Oriented Programming
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Get Current time
Python id()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Functions
Python String ljust()
How to get current date and time in Python?
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Capitalize the First Character of a String
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Multiply Two Matrices
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python List Comprehension
Python Set discard()
Python divmod()
Python String lstrip()
Python Set clear()
Python int()
Python zip()
Python Program to Find Factorial of Number Using Recursion
Python Anonymous / Lambda Function
Python exec()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Find the Sum of Natural Numbers
Python Program to Convert Celsius To Fahrenheit
Python Generators