Skip to content

Instantly share code, notes, and snippets.

@dusansimic
Created August 2, 2016 15:46
Show Gist options
  • Save dusansimic/0cb186cda1a4878892aa61ea7e35eec7 to your computer and use it in GitHub Desktop.
Save dusansimic/0cb186cda1a4878892aa61ea7e35eec7 to your computer and use it in GitHub Desktop.
Simple progress bar in python.
import time
import sys
toolbar_width = 40
current = 0
for i in range(1, 101):
time.sleep(0.1)
temp = int(round((40 * i) / 100, 0))
if current < temp or i <= 100:
sys.stdout.write("\b" * (toolbar_width+7))
sys.stdout.write("[")
sys.stdout.write("=" * temp)
sys.stdout.write(" " * (toolbar_width-temp))
sys.stdout.write("] ")
sys.stdout.write("{}%".format(i))
sys.stdout.flush()
current = temp
sys.stdout.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment