Answers for "write console output in same place"

0

write console output in same place

The simplest way, if you only ever need to update a single line (for instance, creating a progress bar), is to use '\r' (carriage return) and sys.stdout:

import sys
import time

for i in range(10):
    sys.stdout.write("\r{0}>".format("="*i))
    sys.stdout.flush()
    time.sleep(0.5)
If you need a proper console UI that support moving the pointer etc., use the curses module from the standard library
Posted by: Guest on April-14-2022

Python Answers by Framework

Browse Popular Code Answers by Language