
test_count = 0
while test_count <= 100:
print test_count
test_count +=1
Currently this counter is printing on next line but I am looking for way to overwrite it on "0".
Use the \r carriage-return character with sys.stdout.flush.
import sys
import time # for invoking time.sleep(n_seconds) inside loop
counter = 0
while counter <= 100:
time.sleep(1)
counter += 1
sys.stdout.write("\rTesting (%ss elapsed)" % counter)
sys.stdout.flush()
Use \r and add a , at the end of your print statement to not automatically write a newline as in the code below.
Also, see the python-progressbar library for some nice text implementations of progress bars.
import time # Added to demonstrate effect
test_count = 0
while test_count <= 100:
print "\r%3d" % test_count,
time.sleep(0.1)
test_count +=1
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