[Tutor] Printing a progress bar

Terry Carroll carroll at tjc.com
Thu Jun 24 02:12:33 EDT 2004

On Thu, 17 Jun 2004, Dave S wrote:

> Terry Carroll wrote:
> >I use Randy Pargman's progress bar from 
> >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/168639 ; I find it 
> >does the job nicely.
> >  
> >
> I will combine this class with backspacing to hopefully produce a static 
> line with a dynamic progress bar !

Don't sweat the backspacing.  Look at the examples on that web page.  The 
line printing the progress bar string looks like this:

  print prog, "\r",

This prints the string named prog, which is your progress-bar, followed 
by a return ("\r"), which sets up the curser back to column 1, no 
backspacing needed.  Then the newline that's normallt added to a printed 
statement is supressed, due to the trailing comma.

That's one thing I like about this progress bar; you just print it, and 
that's it, no counting, no backspacing, none of that.

Just remember when you're done to do that final bare "print" statement, 
because otherwise you'll still be poised at the beginning of the line for 
your next print statement, and your line will look messy, with a progress 
bar partially overwritten by your next print.

More information about the Tutor mailing list