Single line output, updating output in place

exarkun at exarkun at
Thu Sep 24 06:23:50 CEST 2009

On 04:11 am, tusklahoma at 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 
>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 
>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', 
>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 
>what it is or where to find information on it. It's an escape code, 
>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, 
>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


More information about the Python-list mailing list