[Tutor] Writing to the terminal?
carroll at tjc.com
Sun Dec 12 21:44:21 CET 2010
On Fri, 10 Dec 2010, Modulok wrote:
> Assume I'm working in a command shell on a terminal. Something like
> tcsh on xterm, for example. I have a program which does *something*.
> Let's say it counts down from 10. How do I print a value, and then
> erase that value, replacing it with another value? Say I had something
> like '10' that appears, then wait a second, then the 10 is replaced by
> '9'... '8'.. and so forth.
for t in range(10,0, -1):
print "%s \x0D" %t,
print # get to next line
The magic is \0x0D, which resets to the front of the line; and the
trailing comma, which suppresses starting the next print on a new line.
More information about the Tutor