Skip to content

Instantly share code, notes, and snippets.

@wynnzen
Last active August 29, 2015 14:00
Show Gist options
  • Save wynnzen/2143cda66e2cf735595f to your computer and use it in GitHub Desktop.
Save wynnzen/2143cda66e2cf735595f to your computer and use it in GitHub Desktop.
python terminal progress
import sys
import time
# Output example: [======= ] 75%
# width defines bar width
# percent defines current percentage
def progress(width, percent):
print "%s %d%%\r" % (('%%-%ds' % width) % (width * percent / 100 * '='), percent),
if percent >= 100:
print
sys.stdout.flush()
# Simulate doing something ...
for i in xrange(100):
progress(50, (i + 1))
time.sleep(0.1) # Slow it down for demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment