Skip to content

Instantly share code, notes, and snippets.

@GuoJing
Created May 17, 2016 06:20
Show Gist options
  • Save GuoJing/92dcfadf99eb8729c8d528a17ff025cb to your computer and use it in GitHub Desktop.
Save GuoJing/92dcfadf99eb8729c8d528a17ff025cb to your computer and use it in GitHub Desktop.
Python Progress Bar
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