I am new to python, and coding in general. Looking at the code below, why is my master file writing the lines from each text file twice?
The combined file I am getting looks like this:
text from file1
text from file2
text from file3
text from file1
text from file2
text from file3
Any help is appreciated.
Code:
import os
import glob
FileName = "master.txt"
fout = open(FileName, "w")
for filename in glob.glob("*txt"):
fin = open(filename, "r")
lines = fin.readlines()
fin.close()
for lidx in lines:
fout.write( "%s" % lidx )
fout.close()
The combined file I am getting looks like this:
text from file1
text from file2
text from file3
text from file1
text from file2
text from file3
Any help is appreciated.
Comment