Last active
August 29, 2015 14:24
-
-
Save akleemans/e92b9a3373f424e6b29b to your computer and use it in GitHub Desktop.
Simple progress bar in Python
This file contains hidden or 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 time | |
import sys | |
def update_progress(progress): | |
progress = round(progress*100, 1) | |
barLength = 20 | |
block = int(round(barLength*progress/100)) | |
text = "\rProgress: [{0}] {1}%".format( "#"*block + "-"*(barLength-block), progress) | |
sys.stdout.write(text) | |
sys.stdout.flush() | |
print "Starting work..." | |
for i in range(151): | |
time.sleep(0.05) | |
update_progress(i/150.0) | |
print "\nDone." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment