Skip to content

Instantly share code, notes, and snippets.

@akleemans
Last active August 29, 2015 14:24
Show Gist options
  • Save akleemans/e92b9a3373f424e6b29b to your computer and use it in GitHub Desktop.
Save akleemans/e92b9a3373f424e6b29b to your computer and use it in GitHub Desktop.
Simple progress bar in Python
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