Single line output, updating output in place

Donavan Lance tusklahoma at gmail.com
Thu Sep 24 06:29:49 CEST 2009


Sweet, thanks for the information. Lots to learn.

On Thu, Sep 24, 2009 at 12:23 AM, <exarkun at twistedmatrix.com> wrote:

> On 04:11 am, tusklahoma at gmail.com wrote:
>
>> Hello, I'm a newb and have been playing with Python trying to print a
>> changing value to the screen that updates as the value changes. I have
>> this
>> code, which is pretty much doing what I want:
>>
>> #!/usr/bin/env python3
>>
>> import time
>>
>> text = input('Please enter something: ')
>>
>> for c in text:
>>   print('This is what you entered:', '{0}'.format(c), '\033[A')
>>   if c == text[-1]:
>>       print('\n')
>>   time.sleep(1)
>>
>>
>>
>> Which will output: "This is what you entered: <text>" with text constantly
>> changing. It all stays on the same line, which is what I'm shooting for.
>> So
>> my question is, the little bit that allows me to do this, the '\033[A', I
>> don't really know what that is. I was looking at other code while trying
>> to
>> figure this out, and '\033[A' was used to do this, but I don't really know
>> what it is or where to find information on it. It's an escape code, isn't
>> it? But is it in Python, in Bash, or what? Forgive me if my question is
>> hazy, I'm just not sure why adding '\033[A' got it working for me, where
>> would I find the information that would have enabled me to know that this
>> is
>> what I needed to use?
>>
>
> Its a vt102 control sequence.  It means "move the cursor up one row". vt102
> is something your terminal emulator implements (or, heck, maybe you have a
> real physical vt102 terminal.... nah).  To Python, it's just a few more
> meaningless bytes.
>
> You can read all about vt102 on vt100.net:
>
>   http://vt100.net/docs/vt102-ug/
>
> Jean-Paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090924/fe46b960/attachment.html>


More information about the Python-list mailing list