Skip to content

Instantly share code, notes, and snippets.

@bruxisma
Created August 11, 2010 07:21
Show Gist options
  • Save bruxisma/518618 to your computer and use it in GitHub Desktop.
Save bruxisma/518618 to your computer and use it in GitHub Desktop.
def progress_bar(iterable, fill='=', empty='.', size=60):
count = len(iterable)
def show(i):
x = int(size * i / count)
sys.stdout.write('[{0}{1}] {2}/{3}\r'.format(fill * x, empty * (size - x), i, count))
sys.stdout.flush()
show(0)
for i, item in enumerate(iterable):
yield item
show(i + 1)
sys.stdout.write('\n')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment