Print a carriage return \rand it will return the cursor to the beginning of the line. Make sure that you do not print a new line \nat the end, because you cannot return lines. This means you need to do something like:
import time
import sys
sys.stdout.write('29 seconds remaining')
time.sleep(1)
sys.stdout.write('\r28 seconds remaining')
(Unlike use print, which adds a new line at the end of what it writes to stdout.)
source
share