On 25May2017 20:37, Mahmood Naderan <nt_mahm...@yahoo.com> wrote:
Cameron, thanks for the points. In fact the file name contains multiple '_'
characters. So, I appreciate what you recommended.
filenames = {}
for name in glob.glob('*chunk_*'):
left, right = name.rsplit('_', 1)
if left.endswith('chunk') and right.isdigit():
filenames[int(right)] = filename
sorted_filenames = [ filenames[k] for k in sorted(filenames.keys()) ]
It seems that 'filename' should be 'right'.
No, 'filename' should be 'name': the original filename. Thanks for the catch.
The idea is to have a map of int->filename so that you can open the files in
numeric order. So 'right' is just the numeric suffix - you need 'name' for the
open() call.
Cheers,
Cameron Simpson <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list