Created
May 17, 2016 06:20
-
-
Save GuoJing/92dcfadf99eb8729c8d528a17ff025cb to your computer and use it in GitHub Desktop.
Python Progress Bar
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
import sys | |
def print_progress(iteration, total, prefix = '', suffix = '', decimals = 2, barLength = 100): | |
filledLength = int(round(barLength * iteration / float(total))) | |
percents = round(100.00 * (iteration / float(total)), decimals) | |
bar = '#' * filledLength + '-' * (barLength - filledLength) | |
sys.stdout.write('%s [%s] %s%s %s\r' % (prefix, bar, percents, '%', suffix)), | |
sys.stdout.flush() | |
if iteration == total: | |
print("\n") | |
items = ['A', 'B', 'C', 'D', 'E'] | |
i = 0 | |
l = len(items) | |
print_progress(i, l, prefix = 'Progress:', suffix = 'Complete', barLength = 50) | |
for item in items: | |
i += 1 | |
print_progress(i, l, prefix = 'Progress:', suffix = 'Complete', barLength = 50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment