\r functionality

Markus Weihs mweihs at gmx.at
Tue May 17 06:30:10 EDT 2005


Hi!

> in c and c++ there is a useful way to refresh an output line in printf
> and cout using \r meta command. So for example in the wget application
> the progress of the download is updated on the same output line of the
> screen. From an intital investigation python seems to lack this. Is
> this correct?

No. Well, I think you can't do it with print, but you can do this:

import sys
import time

signs = "|/-\\"
while 1:
    for i in signs:
        sys.stdout.write(i+"\r")
        sys.stdout.flush()
        time.sleep(0.2)


Regards, Markus



More information about the Python-list mailing list