help with printing to stdout...

D'Arcy J.M. Cain darcy at
Sun Mar 8 13:48:40 CET 2009

On Sun, 8 Mar 2009 01:59:03 -0800
Chris Rebert <clp2 at> wrote:
> > etc taking up lots and lots of lines of output... So, how can I make it
> > write the percentage on the same line eg.
> Use the carriage return character to overwrite the line (you'll need
> to forego `print`):

Why do you say that?

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

while working:
  print '\r'+percent,

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

Nope.  You just need to make sure that it never gets shorter which is
the case here.  If it wasn't then:

while working:
  print '\r'+percent+'     ',

D'Arcy J.M. Cain <darcy at>         |  Democracy is three wolves                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

More information about the Python-list mailing list