I'm trying to rewrite on two lines on my terminal from a Python3 script.
Let's take a quick example:
import time
for n in range(1, 10):
print(n)
print(n*2)
time.sleep(1)
When i launch my script I'd like to have this output :
bla@bla:/tmp$ python3 test.py
1
2
Then a second later (after the sleep) I want the 2 numbers to be "replaced by the new output" like this :
bla@bla:/tmp$ python3 test.py
2
4
and so on...
What have I tested ?
- I've tried to put
os.system("clear")
at the begining of my for loop, but it's pretty uggly and it doesn't do what I want... - I've tried to put
end '\r'
at the end of my print as suggested here - I've tried to launch this commands with
os.system()
but it didn't work
Do you have any solutions ? Thanks for your help.