Created
July 7, 2021 11:43
-
-
Save FlxVctr/95abee5c5d584064673bbe887c711873 to your computer and use it in GitHub Desktop.
A function to overwrite the last line in the terminal/stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Usage: | |
previous_text_length = overwrite('text to be written', 0) | |
previous_text_length = overwrite('next text to be written', previous_text_length) | |
''' | |
def overwrite(text, previous): | |
print('\b' * previous, ' ' * previous, end="\r") | |
print(text, end="") | |
sys.stdout.flush() | |
return len(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment