Add Progress Bars To Your Python Loops
Feb 11th, 2013Instead of printing out indices or other info at each iteration of your Python loops to see the progress, you can easily add a progress bar.
For each of your loop
for x in my_list:
# do stuff
wrap the object on which you iterate with pbar()
.
from progressbar import ProgressBar
pbar = ProgressBar()
for x in pbar(my_list):
# do stuff
and it will display a progress that automatically updates itself after each iteration of the loop.
28% |###################### |
It’s great if your run long script and you want to have an idea of how long it is going to run.
Installation
pip install progressbar
Customize it
There are also a ton of customization options available. Here is an example of a progress bar that displays the number of iterations done over the total number of iterations, an estimation of the remaining running time (!) and the “loop speed”, here 1.18 iterations per seconds.
2401 of 1958 [------------ ] ETA: 0:27:27 (at 1.18 it/s)
See the package progressbar on Google
code. Run the
examples.py
to have a demo of all the crazy stuff the package allow.