With the backspace sequence \b
, you can erase printed characters.
print('requesting...', end='', flush=True)
heavy_method(...)...
print('\b' * 13, end='', flush=True)
When written with a context manager:
import contextlib
@contextlib.contextmanager
def print_and_erase(text):
print(text, end='', flush=True)
yield
print('\b' * len(text), end='', flush=True)
with print_and_erase('requesting...'):
heavy_method(...)
Comments