You can use \r
instead of \n
in print(..., end='\r')
to move cursor to beginning of line and then you can write in the same place.
Minimal working code
import time
for x in range(100):
print(x, end='\r')
time.sleep(0.1)
I added time.sleep
to slow down it.
If you have to write shorter text in place of longer text then you may have to add spaces at the end of text.
I'm not sure if all terminals/consoles respect \r
.
Some terminals may use other codes to move cursor, clear clear, etc. These codes are used by modules like curses, npyscreen, urwid, asciimatics to create widgets in text mode.
BTW: If you want it to draw progress bar then see module tqdm