Tuesday, June 25, 2013

Python overwrite printed line, e.g. text progress

\r will reset the cursor to the beginning of the line.
>>> for i in range(100):
...    time.sleep(1)
...    sys.stdout.write("\r%d%%" %i)    # or print >> sys.stdout, "\r%d%%" %i,
...    sys.stdout.flush()
...