January 13, 2010

Python - Command Line Progress Bar With Percentage and Elapsed Time Display

Here is a Python module which produces an ascii command line progress bar with percentage and elapsed time display.

code:
progress_bar.py

to use:

from progress_bar import ProgressBar

p = ProgressBar(60)
    
p.update_time(15)
print p
    
p.fill_char = '='
p.update_time(40)
print p

results:

[##########       25%                  ]  15s/60s
[=================67%=====             ]  40s/60s

10 comments:

Anonymous said...

Handy, thanks a bunch!

Corey Gaffney said...
This comment has been removed by the author.
Robert said...

so how to use this is actual code ?
Can you show that in - say - downloading a file ?

Anonymous said...

Note, you can also update the total time using `p.duration = new_time`. It won't take effect until you call `update_time()` though.

Calvin Spealman said...

I'm always surprised how many people don't notice the progressbar module that's been in pypi.

Slestak said...

The couple in pypi that depend on fcntl are unix only.

Billy said...

Thanks, this is great! Just what I was looking for. Or rather thinking about doing myself as an exercise.

Anonymous said...

Nice, simple and compact - Good job!

However there is a module, as pointed out in a previous post in pypi - you could think about submitting this as a stripped down version?

Inversiones en oro said...

The couple in pypi that depend on fcntl are unix only.

Anonymous said...

http://pypi.python.org/pypi/progressbar works in windows too!