Single line output, updating output in place

Chris Rebert clp2 at rebertia.com
Thu Sep 24 00:21:46 EDT 2009


On Wed, Sep 23, 2009 at 9:11 PM, Donavan Lance <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?

http://en.wikipedia.org/wiki/ANSI_escape_code

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list