Command Line Progress Bar

Mitya Sirenef msirenef at lightbird.net
Wed Dec 26 07:33:40 CET 2012


On 12/26/2012 01:17 AM, Kevin Anthony wrote:
> Hello,
> I'm writing a file processing script(Linux), and i would like to have 
> a progress bar.  But i would also like to be able to print messages. 
>  Is there a simple way of doing this without implementing something 
> like ncurses?
>
> -- 
> Thanks
> Kevin Anthony
> www.NoSideRacing.com <http://www.NoSideRacing.com>


Sure, you just need to print messages then the progress bar, without 
printing newline, then
sys.stdout.flush(), then in the next loop start by printing '\r' to 
erase the progress bar.

That is, if you want messages to scroll up. You can also use half a line 
for the progress
bar and the other half for a short message, then you print both with 
sys.stdout.flush()
and erase both with '\r'.

  - mitya


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/




More information about the Python-list mailing list