Skip to content

Instantly share code, notes, and snippets.

@zPrototype
Last active February 22, 2020 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zPrototype/720a742db1e110b9eea7a963b91ebdc3 to your computer and use it in GitHub Desktop.
Save zPrototype/720a742db1e110b9eea7a963b91ebdc3 to your computer and use it in GitHub Desktop.
Python progressbar with the help from the legend developer himself @iCaotix
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