Last active
February 22, 2020 00:43
-
-
Save zPrototype/720a742db1e110b9eea7a963b91ebdc3 to your computer and use it in GitHub Desktop.
Python progressbar with the help from the legend developer himself @iCaotix
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 | |
import os | |
def print_progressbar(percentage): | |
columns = int(os.popen('stty size', 'r').read().split()[1]) # length of current line | |
columns -= 7 # subtract formatting [] xxx% | |
num_hashes = int(columns / 100 * percentage) | |
sys.stdout.write("\r") | |
sys.stdout.write("[%s%s] %s%s" % (num_hashes * "#", (columns - num_hashes) * " ", percentage, "%")) | |
sys.stdout.flush() | |
completion_percentage = 0 | |
print("Progressbar:") | |
while True: | |
if completion_percentage > 100: | |
print_progressbar(100) | |
break | |
print_progressbar(int(completion_percentage)) | |
time.sleep(.1) | |
completion_percentage += 1 | |
print("") | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment