Skip to content

Instantly share code, notes, and snippets.

@mrtazz
Forked from kennethreitz/console_progress.py
Created June 24, 2010 08:59
Show Gist options
  • Save mrtazz/451191 to your computer and use it in GitHub Desktop.
Save mrtazz/451191 to your computer and use it in GitHub Desktop.
import sys
import time
def progressbar(it, prefix = "", size = 60):
count = len(it)
def _show(_i):
x = int(size*_i/count)
sys.stdout.write("%s[%s>%s] %i/%i\r" % (prefix, "="*x, "-"*(size-x), _i, count))
sys.stdout.flush()
_show(0)
for i, item in enumerate(it):
yield item
_show(i+1)
sys.stdout.write("\n")
sys.stdout.flush()
for i in progressbar(range(15), "Computing: ", 40):
time.sleep(0.1) # long computation
Computing: [........................................] 0/15
...
Computing: [########................................] 3/15
...
Computing: [########################################] 15/15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment