Just to add to this. If you want to return to the beginning and erase the contents of the line, you can do that like this:
text = "Here's a piece of text I want to overwrite"
repl = "BALEETED!" # What we want to write
print(text, end="\r") # Write the text and return
print(f'\r{repl: <{len(text)}}')
That last line might need a bit of explaining, so I'll break it down:
f'SOMETHING {var}'
is an f-string, equivalent to 'SOMETHING {}'.format('HERE')
. It's available in Python 3.6+
So replacing the hard-coded values for variables, we're returning to the beginning and then writing the replacement string, followed by enough spaces to replace the original text. If you want to use the old format method which is probably more clear in this case:
print('\r{0: <{1}}'.format(repl, len(text)))
# Which becomes when extrapolated:
print('BALEETED ')
For bonus points, you don't need to use spaces, you can use anything:
print('\r{0:░<{1}}'.format(repl, len(text)))
# Which becomes when extrapolated:
print('DELETED░░░░░░░░░░░░░░░░░░░░░░░░░░░░░')
Or for extra BONUS make it into a function:
from time import sleep
def overprint(text,repl, t=1, char=" "):
print(text, end="\r")
sleep(t)
print('\r{0:{1}<{2}}'.format(repl, char, len(text)))
overprint("The bomb will explode in one sec...", "BOOM!")