How to give multiple prints in python in the same place of the terminal?

1

Having the following code as a base:

for x in range(100):
    print("{}%".format (x))

How could it be done so that instead of each value appeared on a different line but instead replaced on the same line.

Example in place of terminal:
1
2
3 4
5
Have the first 1 after it "disappears" and appear the 2 and so on until you reach the 5?

I know you can do this using C .

    
asked by anonymous 20.09.2017 / 13:30

1 answer

1

I researched a little and I managed to do it this way:

import sys
import time
for x in range(101):
    print("{}%".format (x))
    sys.stdout.write("3[F")
    time.sleep(0.1)

What causes the text to be replaced is this call: sys.stdout.write("3[F") , so I understand it clears the line.

    
20.09.2017 / 13:43