Created
August 2, 2016 15:46
-
-
Save dusansimic/0cb186cda1a4878892aa61ea7e35eec7 to your computer and use it in GitHub Desktop.
Simple progress bar in python.
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 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