I am trying to print in the exact same spot:
for i in range(10):
print("ok\r"),
However, this prints 10 oks in different lines:
ok
ok
...
I tried putting the \r in the front of the string as well. In this case, I get a blank line then 10 oks:
[blank]
ok
ok
...
I also tried the following
import sys
for i in range(10):
sys.stdout.write('ok\r')
sys.stdout.flush()
But I get the same exact thing. I am on Python 2.7 in pyscripter, what am I doing wrong? I also tried in IDLE, and there 'okokokokokokokokokok' is the result when \r is on the end, and ' ok ok ok ok ok ok ok ok ok ok' is the result when it is in the front.
Edit: I am on windows 7
Any help is highly appreciated!
Try the following code, it works on ubuntu, I added a time.sleep call so you can see what is actually happening:
import time
for i in range(10):
print(str(i),end='\r')
time.sleep(.4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With