(iterable, length=None, prefix='Processing', oneline=True,
                      stream=None, offset=0, step=None)
Turns 'iterable' into a generator which prints a progress bar.

    :param oneline: Set to False to print each update on a new line.
        Useful if there will be other things printing to the terminal.
        Set to "concise" to use exactly one line for all output.
    :param offset: Number of items already/previously iterated.
    :param step: deprecated, not used
Turns 'iterable' into a generator which prints a progress bar.
Turns iterable into a generator which prints a progress bar .
def with_progress_bar(iterable, length=None, prefix='Processing', oneline=True,
                      stream=None, offset=0, step=None):
    """Turns 'iterable' into a generator which prints a progress bar.

    :param oneline: Set to False to print each update on a new line.
        Useful if there will be other things printing to the terminal.
        Set to "concise" to use exactly one line for all output.
    :param offset: Number of items already/previously iterated.
    :param step: deprecated, not used
    """
    if stream is None:
        stream = sys.stdout
    if length is None:
        if hasattr(iterable, "__len__"):
            length = len(iterable)
        else:
            raise AttributeError(
                "'{}' object has no len(), you must pass in the 'length' parameter"
                .format(type(iterable))
            )

    granularity = min(50, length or 50)
    start = datetime.now()

    info_prefix = '' if oneline else f'{prefix} '

    def draw(position, done=False):
        overall_position = offset + position
        overall_percent = overall_position / length if length > 0 else 1
        dots = int(round(min(overall_percent, 1) * granularity))
        spaces = granularity - dots
        elapsed = (datetime.now() - start).total_seconds()
        percent = position / (length - offset) if length - offset > 0 else 1
        remaining = (display_seconds((elapsed / percent) * (1 - percent))
                     if position > 0 else "-:--:--")

        print(prefix, end=' ', file=stream)
        print("[{}{}]".format("." * dots, " " * spaces), end=' ', file=stream)
        print("{}/{}".format(overall_position, length), end=' ', file=stream)
        print("{:.0%}".format(overall_percent), end=' ', file=stream)
        if overall_position >= length or done:
            print("{} elapsed".format(datetime.now() - start), end='', file=stream)
        else:
            print("{} remaining".format(remaining), end='', file=stream)
        print(("\r" if oneline and not done else "\n"), end='', file=stream)
        stream.flush()

    if oneline != "concise":
        print("{}Started at {:%Y-%m-%d %H:%M:%S}".format(info_prefix, start), file=stream)
    should_update = step_calculator(length, granularity)
    i = 0
    try:
        draw(i)
        for i, x in enumerate(iterable, start=1):
            yield x
            if should_update(i):
                draw(i)
    finally:
        draw(i, done=True)
    if oneline != "concise":
        end = datetime.now()
        print("{}Finished at {:%Y-%m-%d %H:%M:%S}".format(info_prefix, end), file=stream)
        print("{}Elapsed time: {}".format(info_prefix, display_seconds((end - start).total_seconds())), file=stream)
def with_progress_bar ( iterable , length = None , prefix = 'Processing' , oneline = True , stream = None , offset = 0 , step = None ) : if stream is None : stream = sys . stdout if length is None : if hasattr ( iterable , "__len__" ) : length = len ( iterable ) else : raise AttributeError ( "'{}' object has no len(), you must pass in the 'length' parameter" . format ( type ( iterable ) ) ) granularity = min ( 50 , length or 50 ) start = datetime . now ( ) info_prefix = '' if oneline else f'{prefix} ' def draw ( position , done = False ) : overall_position = offset + position overall_percent = overall_position / length if length > 0 else 1 dots = int ( round ( min ( overall_percent , 1 ) * granularity ) ) spaces = granularity - dots elapsed = ( datetime . now ( ) - start ) . total_seconds ( ) percent = position / ( length - offset ) if length - offset > 0 else 1 remaining = ( display_seconds ( ( elapsed / percent ) * ( 1 - percent ) ) if position > 0 else "-:--:--" ) print ( prefix , end = ' ' , file = stream ) print ( "[{}{}]" . format ( "." * dots , " " * spaces ) , end = ' ' , file = stream ) print ( "{}/{}" . format ( overall_position , length ) , end = ' ' , file = stream ) print ( "{:.0%}" . format ( overall_percent ) , end = ' ' , file = stream ) if overall_position >= length or done : print ( "{} elapsed" . format ( datetime . now ( ) - start ) , end = '' , file = stream ) else : print ( "{} remaining" . format ( remaining ) , end = '' , file = stream ) print ( ( "\r" if oneline and not done else "\n" ) , end = '' , file = stream ) stream . flush ( ) if oneline != "concise" : print ( "{}Started at {:%Y-%m-%d %H:%M:%S}" . format ( info_prefix , start ) , file = stream ) should_update = step_calculator ( length , granularity ) i = 0 try : draw ( i ) for i , x in enumerate ( iterable , start = 1 ) : yield x if should_update ( i ) : draw ( i ) finally : draw ( i , done = True ) if oneline != "concise" : end = datetime . now ( ) print ( "{}Finished at {:%Y-%m-%d %H:%M:%S}" . format ( info_prefix , end ) , file = stream ) print ( "{}Elapsed time: {}" . format ( info_prefix , display_seconds ( ( end - start ) . total_seconds ( ) ) ) , file = stream )