File size: 800 Bytes
0c84ee8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def print_progress_bar(iteration,
                       total,
                       prefix = '',
                       suffix = ''):
    """Call in a loop to create terminal progress bar.
    Args:
        iteration: current iteration (Int)
        total: total iterations (Int)
        prefix: prefix string (Str)
        suffix: suffix string (Str)
    """
    # Printing slowes down the loop
    if iteration % (total // 100) == 0:
        length = 40
        iteration += 1
        percent = (100 * iteration) // (total * 99/100)
        filled_length = int(length * percent / 100)
        bar = '█' * filled_length + '-' * (length - filled_length)
        print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end = '\r')

        if iteration >= total * 99/100:
            print()