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 String encode()
Python Program to Calculate the Area of a Triangle
Python min()
Python String center()
Python Program to Check if a Key is Already Present in a Dictionary
Python String maketrans()
Python File I/O Operation
Python Program to Convert Kilometers to Miles
Python Program to Safely Create a Nested Directory
Python RegEx
Python List clear()
Python Dictionary setdefault()
Python Data Structures and Algorithms - Benjamin Baka
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python pass statement
Python String format_map()
Python Program to Count the Number of Occurrence of a Character in String
Python Set clear()
Python Custom Exceptions
Python String istitle()
Python Program to Print Hello world!
Python Dictionary values()
Python staticmethod()
Python object()
Python strptime()
Python Set difference()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python hash()
Python String isdigit()
Python Program to Merge Two Dictionaries
Python Program to Get the Last Element of the List
Python String rsplit()