def get_files_from_textfile(textfile_handler):
    """Yield the file names and widths by parsing a text file handler."""
    for line in textfile_handler:
        line = line.rstrip()
        try:
            (image_name, width) = line.rsplit(',', 1)
            width = int(width)
        except ValueError:
            image_name = line
            width = None
        yield (image_name, width)
Yield the file names and widths by parsing a text file handler.