Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting already printed in Python

For practice, I'm trying to do some stuff in Python. I've decided to make a simple hangman game - I'm not making a GUI. The game would start with a simple input(). Now, I'd like next line to, beside asking for input, to delete the hidden word. I've tried using \b (backspace character), but it's not working. Something like:

word = input("Your word: ")
for i in range(len(word) + 12):
    print("\b")

Now, printing the backlash character is supposed to delete the input and "Your word", but it isn't doing anything. If I do this in IDLE I get squares, and I get nothing if I open it by clicking.

How to accomplish this? I'm afraid I wasn't too clear with my question, but I hope you'll see what I meant. :)

like image 465
Bane Bojanić Avatar asked Jan 22 '23 20:01

Bane Bojanić


1 Answers

\b does not erase the character before the cursor, it simply moves the cursor left one column. If you want text entry without echoing the characters then look at getpass.

like image 119
Ignacio Vazquez-Abrams Avatar answered Feb 01 '23 06:02

Ignacio Vazquez-Abrams