This question is related to Python concatenate text files
I have a list of file_names
, like [\'file1.txt\', \'file2.txt\', ...].
I wou
try something along this lines:
def read_files(*filenames):
for filename in filenames:
with open(filename,'r') as file_obj:
for line in file_obj:
yield line
you can call it with
for line in read_files("f1.txt", "f2.txt", "f3.txt"):
#... do whatever with the line
or
filenames = ["f1.txt", "f2.txt", "f3.txt"]
for line in read_files(*filenames):
#... do whatever with the line