Skip to content

Instantly share code, notes, and snippets.

@marty-Wallace
Last active March 16, 2017 06:06
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 marty-Wallace/cc4fe14ad1dbec4e7c75c88323a915ae to your computer and use it in GitHub Desktop.
Save marty-Wallace/cc4fe14ad1dbec4e7c75c88323a915ae to your computer and use it in GitHub Desktop.
python progress bar for terminals
import sys
def drawProgressBar(percent_done, barLength = 40):
"""Display an updating progress bar in a terminal
:percent_done: the percent done to display
:barLength: how many chars long the bar is
:returns: None
"""
sys.stdout.write("\r")
progress = ""
for i in range(barLength):
if i <= int(barLength * percent_done):
if i+1 <= int(barLength * percent_done):
progress += "="
else:
progress += ">"
else:
progress += " "
sys.stdout.write("[%s] %.2f%%" % (progress, percent_done * 100))
sys.stdout.flush()
def main():
"""Main function. Displays an example of progress bar
:returns: None
"""
for k in range(1,5):
print("Processing Very Important item %d" % k)
for i in range(50000):
drawProgressBar(i/50000, 20)
for j in range(1000):
pass
print()
# won't run if it's imported
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment