On 2017-05-23 22:14, Mahmood Naderan via Python-list wrote:
OK guys thank you very much. It is better to sort them first.


Here is what I wrote

files =  glob.glob('*chunk*')

Here you're making a list of (index, name) pairs:

sorted=[[int(name.split("_")[-1]), name] for name in files]

but you haven't sorted them. You also need:

sorted.sort()

with open('final.txt', 'w') as outf:
       for fname in sorted:
             with open(fname[1]) as inf:

An alternative to this:

        for line in inf:
          outf.write(line)
is:
          outf.writelines(inf)


and it works
Regards,
Mahmood

[snip]
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to