Updating a line of text in Python 3
Question: I want to update a line of text, so that I don't have too many lines of
output. Look at an installer program for an example:

Instead of...

> Installation status: 1%
>
> Installation status: 2%
>
> Installation status: 3%
>
> ...

... I want the same line to update every time the percentage changes.

I already found a way to do so (well, it's actually tricking the user), but it
is kind of bad, because all the lines from above disappear. I'm talking about
importing 'os' and then doing 'os.system("clear")'.

Is there a better way of doing so?

BTW: I'm talking about a few hundred changes per second. The installer is just
an example.


Answer: Use the appendage `\r` and then `sys.stdout.flush()`

To continue to use the installer example:

    
    
    import sys
    import time
    for i in range(100):
        sys.stdout.write("\rInstallation Progress: %d percent" % i)
        time.sleep(.05)
        sys.stdout.flush()
    

Happy coding!

EDIT--I used % to represent percent completed. The result was an incomplete
placeholder. My apologies!

