Pages

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:

  1. Handy, thanks a bunch!

    ReplyDelete
  2. This comment has been removed by the author.

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

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

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

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

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

    ReplyDelete
  8. 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?

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

    ReplyDelete
  10. AnonymousMay 29, 2011

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

    ReplyDelete