Single line output, updating output in place

Donavan Lance tusklahoma at gmail.com
Thu Sep 24 00:11:53 EDT 2009


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090924/ecad226a/attachment.html>


More information about the Python-list mailing list