Concatenating files in order
Mahmood Naderan
nt_mahmood at yahoo.com
Tue May 23 15:29:39 EDT 2017
Hi,
There are some text files ending with _chunk_i where 'i' is an integer. For example,
XXX_chunk_0
XXX_chunk_1
...
I want to concatenate them in order. Thing is that the total number of files may be variable. Therefore, I can not specify the number in my python script. It has to be "for all files ending with _chunk_i".
Next, I can write
with open('final.txt', 'w') as outf:
for fname in filenames:
with open(fname) as inf:
for line in inf:
outf.write(line)
How can I specify the "filenames"?
Regards,
Mahmood
More information about the Python-list
mailing list