The question says it all, but basically I would like to replace the previous line with as little hassle as possible
Thanks in advance
No, the question does NOT say it all – it's incredibly vague.
Tell us EXACTLY what you're trying to do. Are you talking about editing a source listing? Drawing a line on the screen? Altering a text file from a running program? Text output during a program?
You can use ANSI escape sequences for a *nix like terminal (Linux, etc.). They begin with Esc character code beginning with backslash (\033) a left bracket ( [ ) and then the ANSI code. You may need to do something different for Windows.
from time import sleep
print("Demo how to cursor up and erase line:")
You need to be far more specific. Perhaps add some pseudo code so that us programmers can see what you're trying to do.