Skip to content

Instantly share code, notes, and snippets.

@dolphin2410
Created July 14, 2021 13:54
Show Gist options
  • Save dolphin2410/af21342efabca78b630ba919f5baeedf to your computer and use it in GitHub Desktop.
Save dolphin2410/af21342efabca78b630ba919f5baeedf to your computer and use it in GitHub Desktop.
Python CLI progressbar
class ProgressBar():
def __init__(self, size, finishedChar='#', unfinishedChar='-'):
self.size = size
self.finishedChar = finishedChar
self.unfinishedChar = unfinishedChar
def update(self, percent):
ratio_0 = math.floor(percent / (100 / self.size))
ratio_1 = self.size - ratio_0
sys.stdout.write("\r|" + self.finishedChar*ratio_0 + self.unfinishedChar*ratio_1 + "| " + str(math.floor(percent)) + "%")
def remove(self):
sys.stdout.write("\r")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment