help with printing to stdout...

Chris Rebert clp2 at rebertia.com
Sun Mar 8 05:59:03 EDT 2009


On Sun, Mar 8, 2009 at 1:37 AM, Daniel Dalton <d.dalton at iinet.net.au> wrote:
> Hi,
>
> I've got a program here that prints out a percentage of it's
> completion. Currently with my implimentation it prints like this:
> 0%
> 1%
> 2%
> 3%
> 4%
>
> etc taking up lots and lots of lines of output... So, how can I make it
> write the percentage on the same line eg.
> while working:
>  print percent

Use the carriage return character to overwrite the line (you'll need
to forego `print`):

from sys import stdout
while working:
    stdout.write('\r'+percent)

Note that you'll need to ensure that `percent` has constant length
throughout the loop.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list