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 split()
Python List index()
Python Set difference_update()
Python Program to Create Pyramid Patterns
Python String index()
Python List copy()
Python String isdigit()
Python Decorators
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Modules
Python dir()
Python Dictionary update()
Python timestamp to datetime and vice-versa
Python Custom Exceptions
Python List reverse()
Python String lstrip()
Python Operator Overloading
Python Set add()
Python Tuple count()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Check the File Size
Python @property decorator
Python RegEx
Python Dictionary keys()
Python Program to Get Line Count of a File
Python Program to Split a List Into Evenly Sized Chunks
Python delattr()
Python Set issubset()
Python String strip()
Python isinstance()
Python Program to Print Hello world!