Created
December 20, 2016 21:26
-
-
Save Devligue/cc2afe3cc5c5729acb132d6b6ad3a3e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
def print_progress(iteration, total, prefix='', suffix='', | |
decimals=1, bar_length=100): | |
"""Call in a loop to create terminal progress bar. | |
Required keyword arguments: | |
iteration -- current iteration | |
total -- total iterations | |
Optional keyword arguments: | |
prefix -- prefix string (default '') | |
suffix -- suffix string (default '') | |
decimals -- positive number of decimals in percent complete (default 1) | |
bar_length -- character length of bar (default 100) | |
""" | |
str_format = "{0:." + str(decimals) + "f}" | |
percents = str_format.format(100 * (iteration / float(total))) | |
filled_length = int(round(bar_length * iteration / float(total))) | |
bar = u'█' * 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