I am using Python 2.7.13(in Kali 4.9.0 amd64), and I have tried every variation of the print() statement that I can find(with the proper future import statements), and I am ending up with OK on a newline everytime. Here is the code:
from __future__ import print_function
for i in range(0, 10000):
print("\rOK", end="")
I have tried:
single quotes instead of double for end=""
using Python 2.x syntax instead of importing print_function and using 3.0 syntax
end='\r' end="\r"
a space in between the quotes of end=""
When I used the 2.7 syntax, I was able to get the output to stay on the same line but still printing in a row, when I try to use a carriage return to return the cursor to the beginning position(and overwrite previous output), it inserts a newline, even with a terminating comma in my print statement. I have read Question 3249524, along with well over a dozen other explanations for this problem. I have also tried using the sys.stdout functions instead:
import sys
for i in range(10):
sys.stdout.write("\rCountdown: %d" % i)
sys.stdout.flush()
The output of both programs is still on a newline every time. I am at a loss as to how to get it to print in the same place on the same line. Thanks to anyone who can illuminate this issue.