python:progress_bar
Differences
This shows you the differences between two versions of the page.
| python:progress_bar [2010/07/06 07:32] – created tkbletsc | python:progress_bar [2012/08/30 17:33] (current) – tkbletsc | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| import sys | import sys | ||
| - | def progressbar(it, | + | def progressbar(it, |
| - | count = len(it) | + | count = len(it) |
| - | def _show(_i): | + | def _show(_i): |
| - | x = int(size*_i/ | + | if _i % show_every != 0: return |
| - | sys.stdout.write(" | + | x = int(size*_i/ |
| - | sys.stdout.flush() | + | sys.stdout.write(" |
| - | + | sys.stdout.flush() | |
| - | _show(0) | + | |
| - | for i, item in enumerate(it): | + | _show(0) |
| - | yield item | + | for i, item in enumerate(it): |
| - | _show(i+1) | + | yield item |
| - | sys.stdout.write(" | + | _show(i+1) |
| - | sys.stdout.flush() | + | sys.stdout.write(" |
| + | sys.stdout.flush() | ||
| </ | </ | ||
| Line 28: | Line 29: | ||
| time.sleep(0.1) # long computation | time.sleep(0.1) # long computation | ||
| </ | </ | ||
| - | |||
python/progress_bar.1278426739.txt.gz · Last modified: by tkbletsc
