Last active
August 29, 2015 14:00
-
-
Save wynnzen/2143cda66e2cf735595f to your computer and use it in GitHub Desktop.
python terminal progress
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 | |
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: | |
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