Merge pull request #18 from maraujop/develop

Adding kwargs to progress bar, so that bar chars can be customized
This commit is contained in:
Kenneth Reitz
2011-08-12 06:46:42 -07:00
2 changed files with 4 additions and 5 deletions
+2 -1
View File
@@ -14,4 +14,5 @@ Patches and Suggestions
- Morgan Goose
- Travis Swicegood
- Will Thames
- Greg Haskins
- Greg Haskins
- Miguel Araujo <maraujop>
+2 -4
View File
@@ -15,20 +15,18 @@ import sys
STREAM = sys.stderr
BAR_TEMPLATE = '%s[%s%s] %i/%i\r'
BAR_EMPTY_CHAR = '-'
BAR_FILLED_CHAR = '='
DOTS_CHAR = '.'
def bar(it, label='', width=32, hide=False):
def bar(it, label='', width=32, hide=False, bar_empty_char='-', bar_filled_char='='):
"""Progress iterator. Wrap your iterables with it."""
def _show(_i):
x = int(width*_i/count)
if not hide:
STREAM.write(BAR_TEMPLATE % (
label, BAR_FILLED_CHAR*x, BAR_EMPTY_CHAR*(width-x), _i, count))
label, bar_filled_char*x, bar_empty_char*(width-x), _i, count))
STREAM.flush()
count = len(it)