First of all, I am NOT looking for how to print in the same line with the print(some_stuff, end="")
.
In Python 2.7 you could type:
while True:
for i in ["/","-","|","\\","|"]:
print "%s\r" % i,
and it would print, in the SAME line, in the SAME spot those 5 characters, making it look like you had a bar spinning (actually you could try it out). The thing is, I can't do the same thing in Python 3.3, and I've tried several things. My specific application would be a countdown timer... The code is something like this:
import time
t = 120
while t > 0:
t -= 1
print("Time left till next update: %d seconds" % t)
time.sleep(1)
where the output should be the string, with ONLY the number of seconds changing in place... Hope someone can help me with this.
You use end='\r'
as keyword argument:
print("Time left till next update: %d seconds" % t, end='\r')
The default for end
is '\n'
but you can specify your own.
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