Skip to content

Instantly share code, notes, and snippets.

@himaprasoonpt
Created February 9, 2019 13:49
Show Gist options
  • Save himaprasoonpt/37deb3ab2c8d07bcc26490eb60a3a76d to your computer and use it in GitHub Desktop.
Save himaprasoonpt/37deb3ab2c8d07bcc26490eb60a3a76d to your computer and use it in GitHub Desktop.
Bi directional Horizontal Process bar
import sys
def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100,reversed =False):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
bar_length - Optional : character length of bar (Int)
"""
str_format = "{0:." + str(decimals) + "f}"
percents = str_format.format(100 * (iteration / float(total)))
filled_length = int(round(bar_length * iteration / float(total)))
bar = '█' * filled_length + '-' * (bar_length - filled_length)
bar = bar[::-1] if reversed else bar
sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
if iteration == total:
sys.stdout.write('\n')
sys.stdout.flush()
import time
for i in range(1,101):
time.sleep(0.2)
print_progress(iteration=i,total=100,prefix="Prefix",suffix="Suffix",bar_length=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment