"""Utilities that might be useful elsewhere.""" from collections import namedtuple ProgressIndicator = namedtuple( "ProgressIndicator", ("filesize", "processedsize", "currentline", "percent")) def make_progress_calculator(filesize: int): """ Returns a function that takes two arguments, `linenumber` and `linetext` and return a `ProgressIndicator` object with the computed progress. """ processedsize = 0 def __calculator__(linenumber: int, linetext: str) -> ProgressIndicator: nonlocal processedsize processedsize = processedsize + len(linetext) return ProgressIndicator( filesize, processedsize, linenumber, ((processedsize/filesize) * 100)) return __calculator__