Normally print ("{}".foo, end="\r")
works well.
But the exception is when foo
is long, and next time foo
becomes short. The output becomes incorrect. Below is an example:
import time
print ("{}".format(1111), end="\r")
time.sleep(2)
print ("{}".format(2), end="\r")
First Output:
1111
Final Output (after 2 sec) - which is wrong:
2111
Expected Output
2
Attempts
Tried using flush=True
with print
, and sys.stdout.flush()
but without luck.
Tested in Jupyter Notebook and iPython. Any idea how to optimize this in a simple way?