Merge .txt files in python

In this tutorial, we will learn how to merge two .txt files in python. In many situations, you might have to come up with this type of requirements.

I know you are here just because you are in need of this awesome trick to merge two .txt files using Python.

If you don’t know how to merge two .txt files then you are at the right place. Because in this tutorial we gonna find out how to merge .txt file in python.

filenames = ['file1.txt' , 'file2.txt']
with open('file3.txt' , 'w') as outfile:
for names in filenames:
with open(names) as infile:
outfile.write(infile.read())
outfile.write("\n")

Output:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top