I'm writing a program where I want the cursor to print letters on the same line, but then delete them as well, as if a person was typing, made a mistake, deleted back to the mistake, and kept typing from there.
All I have so far is the ability to write them on the same line:
import sys, time
write = sys.stdout.write
for c in text:
write(c)
time.sleep(.5)
Python Remove Character from String using translate() Python string translate() function replace each character in the string using the given translation table. We have to specify the Unicode code point for the character and 'None' as a replacement to remove it from the result string.
You can remove a character from a Python string using replace() or translate(). Both these methods replace a character or string with a given value. If an empty string is specified, the character or string you select is removed from the string without a replacement.
In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.
Python Remove Character from a String – How to Delete Characters from Strings. In Python you can use the replace() and translate() methods to specify which characters you want to remove from a string and return a new modified string result.
write('\b') # <-- backup 1-character
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With