1

In python is there an easy way to rewrite printed line?

But I'm not talking about last printed line because for that is:

print("text", end="\r")

Then my last resort is using os.system("cls") and printing all info with changed line again.

I wanted to recreate anaconda downloading or docker build.

I know maybe it's duplicate question but I haven't found it if so my bad.

Example:

text
text2
text3

After change:

text
hello_world
text3

It could be this code:

import os
print('text')
print('text2')
print('text3')
os.system('cls')
print('text')
print('hello_world')
print('text3')

But with more printed lines it would be quite annoying to always rewriting all lines

Maybe it is C magic that's my only way to describe what they have done in anaconda or docker.

cards
  • 3,936
  • 1
  • 7
  • 25
Gren Man
  • 110
  • 9
  • For unix based operating systems you could use curses or use VT100 terminal control sequences to move around the screen. – tdelaney Feb 18 '23 at 19:05
  • Does this answer your question? [Is there a way to clear your printed text in python?](https://stackoverflow.com/questions/19596750/is-there-a-way-to-clear-your-printed-text-in-python) – Ceres Feb 18 '23 at 19:11

0 Answers0