other.cheap_progress ==================== .. py:module:: other.cheap_progress Functions --------- .. autoapisummary:: other.cheap_progress.progress Module Contents --------------- .. py:function:: progress[T](items: collections.abc.Iterable[T], desc: str = '', total: int = 0) -> collections.abc.Iterator[T] A simple progress iterator that yields items from the given iterable while displaying a progress indicator in place on a single line of stderr. The output is not written to stdout, so the output of the program remains clean (see doctests). for item in progress(range(1_000), desc="Processing"): process(item) Args: items: The iterable of items to process. desc: A description to display alongside the progress. Defaults to "". total: The total number of items, defaults to 0. If 0, it will be inferred from the iterable if possible. Yields: Iterator[T]: The items from the iterable, one by one. >>> tuple(progress(range(5))) (0, 1, 2, 3, 4) >>> tuple(progress(range(5), desc="Processing", total=3)) (0, 1, 2, 3, 4) >>> tuple(progress(range(5), desc="Processing", total=10)) (0, 1, 2, 3, 4) >>> tuple(progress(range(5), desc="Processing", total=-5)) (0, 1, 2, 3, 4) >>> from string import printable >>> tuple(progress(printable, desc="Printable")) # doctest: +ELLIPSIS ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',...