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 compile()
Python String index()
Python Program to Merge Two Dictionaries
Python Sets
Python chr()
Python String rindex()
Python print()
Python Program to Differentiate Between del, remove, and pop on a List
Python strftime()
Python ord()
Python Operators
Python String capitalize()
Python Program to Count the Number of Each Vowel
Python set()
Python Set symmetric_difference_update()
Python String center()
Python Global Keyword
Python Program to Display the multiplication Table
Python Set issuperset()
Python Program to Sort a Dictionary by Value
Python Decorators
Python Program to Find the Square Root
Python Set remove()
Python Program to Create a Countdown Timer
Python Data Types
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Variables, Constants and Literals
Python Program to Compute all the Permutation of the String
Python min()
Python List Comprehension
Python Machine Learning - Sebastian Raschka
Python setattr()