[Tutor] Writing to the terminal?

Steven D'Aprano steve at pearwood.info
Sun Dec 12 22:33:57 CET 2010

Terry Carroll wrote:

> import time
> for t in range(10,0, -1):
>     print "%s \x0D" %t,
>     time.sleep(1)
> print # get to next line
> print "Done!"

Which operating system and terminal did you use?

In my experience, using print is not satisfactory, because the print 
command buffers the output and doesn't actually print anything until 
either a newline or you have a certain number of characters. So the 
above will queue up the following string:

"10 \r9 \r8 \r7 \r6 \r5 \r4 \r3 \r2 \r1 \r\n"

before anything becomes visible, and of course that just looks like "1".


More information about the Tutor mailing list