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 Program to Check the File Size
Python dir()
Python String partition()
Python Program to Convert Bytes to a String
Python Decorators
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Multiply Two Matrices
Python List count()
Python delattr()
Python Program to Measure the Elapsed Time in Python
Python String format_map()
Python Program to Remove Duplicate Element From a List
Python Program to Shuffle Deck of Cards
Python Program to Check If Two Strings are Anagram
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python timestamp to datetime and vice-versa
Python Object Oriented Programming
Python String istitle()
Python String isprintable()
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Find the Square Root
Python Numbers, Type Conversion and Mathematics
Python bytearray()
Python String ljust()
Python Program to Count the Occurrence of an Item in a List
Python dict()
Python map()
Python complex()
Python List insert()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python String strip()
Python Program to Find Factorial of Number Using Recursion