>>> import sys
>>> import time
>>> myList=range(10)
>>> for x in myList:
...     sys.stdout.write(str(x) + "\r")
...     sys.stdout.flush()
...     time.sleep(1)

The "\r" causes a return without a newline feed.
Flush forces the text to be output (instead of getting buffered)

Enjoy!

Todd Maynard




On Wednesday 05 October 2005 02:13 pm, Oliver Maunder wrote:
> Does anyone know how I can update a line of console output without creating
> a new line? I'm not explaning this too well, so here's an example.
>
> When you download a file with wget, the console display looks like this:
>
> 14% [=======> ] 344,192 16.28K/s ETA 02:19
>
> All the figures and the progress bar get continously updated. The only way
> I know of sending output to the console is to use print or
> sys.stdout.write(), but that would give me:
> 14% [=======> ] 344,192 16.28K/s ETA 02:19
> 18% [=========> ] 344,192 16.28K/s ETA 02:19
> 20% [============> ] 344,192 16.28K/s ETA 02:19
>
> ...and that's really not what I'm after!
>
> Any help and ideas would be appreciated
>
> Olly
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to