(options)
return [fn for (_, fn) in sorted(filenames)]
Get the filenames from the command line, optionally sorted by
number, so that IMG_10.png is re-arranged to come after IMG_9.png.
This is a nice feature because some scanner programs (like Image
Capture on Mac OS X) automatically number files without leading zeros,
and this way you can supply files using a wildcard and still have the
pages ordered correctly.
Get the filenames from the command line, optionally sorted by
number, so that IMG_10.png is re-arranged to come after IMG_9.png.
This is a nice feature because some scanner programs (like Image
Capture on Mac OS X) automatically number files without leading zeros,
and this way you can supply files using a wildcard and still have the
pages ordered correctly.
Get the filenames from the command line optionally sorted by number so that IMG_10 . png is re - arranged to come after IMG_9 . png . This is a nice feature because some scanner programs ( like Image Capture on Mac OS X ) automatically number files without leading zeros and this way you can supply files using a wildcard and still have the pages ordered correctly .
def get_filenames(options):
    '''Get the filenames from the command line, optionally sorted by
number, so that IMG_10.png is re-arranged to come after IMG_9.png.
This is a nice feature because some scanner programs (like Image
Capture on Mac OS X) automatically number files without leading zeros,
and this way you can supply files using a wildcard and still have the
pages ordered correctly.

    '''

    if not options.sort_numerically:
        return options.filenames

    filenames = []

    for filename in options.filenames:
        basename = os.path.basename(filename)
        root, _ = os.path.splitext(basename)
        matches = re.findall(r'[0-9]+', root)
        if matches:
            num = int(matches[-1])
        else:
            num = -1
        filenames.append((num, filename))

    return [fn for (_, fn) in sorted(filenames)]
def get_filenames ( options ) : if not options . sort_numerically : return options . filenames filenames = [ ] for filename in options . filenames : basename = os . path . basename ( filename ) root , _ = os . path . splitext ( basename ) matches = re . findall ( r'[0-9]+' , root ) if matches : num = int ( matches [ - 1 ] ) else : num = - 1 filenames . append ( ( num , filename ) ) return [ fn for ( _ , fn ) in sorted ( filenames ) ]