How can I overwrite/print over the current line in Windows command line?
yes:
import sysimport timedef restart_line(): sys.stdout.write('\r') sys.stdout.flush()sys.stdout.write('some data')sys.stdout.flush()time.sleep(2) # wait 2 seconds...restart_line()sys.stdout.write('other different data')sys.stdout.flush()
I know this is old, but i wanted to tell my version (it works on my PC in the cmd, but not in the idle) to override a line in Python 3:
>>> from time import sleep>>> for i in range(400):>>> print("\r" + str(i), end="")>>> sleep(0.5)
EDIT:It works on Windows and on Ubuntu
import sys import timefor i in range(10): print '\r', # print is Ok, and comma is needed. time.sleep(0.3) print i, sys.stdout.flush() # flush is needed.
And if on the IPython-notebook, just like this:
import timefrom IPython.display import clear_outputfor i in range(10): time.sleep(0.25) print(i) clear_output(wait=True)