[Tutor] Writing to the terminal?

Wayne Werner waynejwerner at gmail.com
Sun Dec 12 14:16:21 CET 2010

On Fri, Dec 10, 2010 at 2:38 PM, Corey Richardson <kb1pkl at aim.com> wrote:

> On 12/10/2010 3:34 PM, Wayne Werner wrote:
>> If you just want a single line you can use chr(13) which is a carriage
>> return. If you want a more complex program you'll need a curses type
>> library
>> hth, wayne
>> On 12/10/10, Modulok<modulok at gmail.com>  wrote:
>>> List,
>>> Forgive me if I don't describe this well, I'm new to it:
>>> 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. The point is, I don't want to print to a
>>> new line, nor do I want the new number to appear next to the previous
>>> number... I just want to change it in place. (If that makes any
>>> sense?) Think of console based progress counters in programs like
>>> fetch or wget, or lame.
>>> How do you do this in Python?
>>> -Modulok-
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
> Try that in the interactive interpreter, it doesn't work.
> >>> print "a" + chr(13)
> a
> (Python 2.6.6)

Actually, it does:
 >>> print 'a' + chr(13) + 'b'

The cursor moves back, you just didn't bother to overwrite the 'a'.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101212/fc8111d2/attachment.html>

More information about the Tutor mailing list