Stan Stan - 3 months ago 11x
Python Question

Python to print out status bar and percentage

To implement a status bar like below:

[========== ] 45%
[================ ] 60%
[==========================] 100%

I want to this to be printed out to stdout, and keep refreshing it, not print to another line. How to do this?


There's a Python module that you can get from PyPI called progressbar that implements such functionality. If you don't mind adding a dependency, it's a good solution. Otherwise, go with one of the other answers.

A simple example of how to use it:

import progressbar
from time import sleep
bar = progressbar.ProgressBar(maxval=20, \
    widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
for i in xrange(20):

To install it, you can use easy_install progressbar, or pip install progressbar if you prefer pip.