Re printing on same line.

Robert Bauck Hamar roberth+news at ifi.uio.no
Fri Jun 15 13:09:13 EDT 2007


Jerry Hill wrote:

> On 6/15/07, HMS Surprise <john at datavoiceint.com> wrote:
>> I want to print a count down timer on the same line. I tried
>>
>>     print '\r', timeLeft,
>>
>> which just appends to the same line.
> 
> Sounds to me like whatever you're printing to doesn't do what you
> expect when it encounters a carriage return (\r).  Is your program
> running in a terminal?  Both the windows cmd.exe shell and bash under
> linux seem to do the right thing when encountering a '\r'.

Actually, bash has nothing to do with how the terminal handles \r. The job
of the shell (bash, ksh, csh, sh ...) is to execute your script when you
type its name.

Outputting a \r might or might not move the cursor to the beginning of the
line. It's completely system specific, and even on the same OS, it depends
on the capabilities of the actual terminal the programs run on, and on some
terminal emulators it might depend on configuration settings.

If you need to explore the capabilities of the terminal, curses will be a
good place to start.

-- 
rbh



More information about the Python-list mailing list