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 Dictionary popitem()
Python Program to Iterate Through Two Lists in Parallel
Python String isnumeric()
Python eval()
Python sorted()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python List append()
Python Program to Add Two Numbers
Python Program to Generate a Random Number
Python String ljust()
Python vars()
Python Program to Display Fibonacci Sequence Using Recursion
Python Dictionary copy()
Python Program to Create a Long Multiline String
Python pow()
Python Operators
Python frozenset()
Python dict()
Python Program to Display Calendar
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Program to Split a List Into Evenly Sized Chunks
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Program to Represent enum
Python Program to Check if a Number is Positive, Negative or 0
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python open()
Python List clear()
Python max()
Python Program to Print Output Without a Newline
Python Dictionary fromkeys()
Python reversed()
Python Dictionary values()