Skip to content

Instantly share code, notes, and snippets.

@luminousmen
Created September 26, 2019 17:50
Show Gist options
  • Save luminousmen/e02c550b446ed4d966744042cfad7e09 to your computer and use it in GitHub Desktop.
Save luminousmen/e02c550b446ed4d966744042cfad7e09 to your computer and use it in GitHub Desktop.
def tqdm(iteration, total: int, prefix: str = '', suffix: str = '', decimals: int = 1, bar_length: int = 100) -> None:
"""Call in a loop to create terminal progress bar
"""
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)
sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
if iteration == total:
sys.stdout.write('\n')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment