hypnoz
hypnoz

Reputation: 33

Python - Clearing the user input?

I'm pretty new to python, I'm using version 3.3.3.

Let's say we have this script:

name = "user"
say = input("Say: ")
print (name, "said:",say)

If I run it, the output will be:

Say: mytext
user said: mytext

I wanna know, is there a way to clear/delete the 'Say: mytext'? Just to make it a little bit clearer:

I want:
    user said: hi
    user said: test
    user said: ..

I don't want:
    Say: hi
    user said: hi
    Say: test
    user said: test

That's all, thnx in advance:)

Upvotes: 3

Views: 4055

Answers (2)

julienc
julienc

Reputation: 20335

You cannot simply tell the input function to hide the user input. But you can use the getpass function which will work all the same:

from getpass import getpass

name = "user"
say = getpass(prompt="")
print (name, "said:",say)

Just remember to set the prompt parameter to the value you want (empty string in this case), otherwise Password:\n will be displayed.

Upvotes: 1

pacholik
pacholik

Reputation: 8982

name = "user"
say = input("Say: ")
sys.stdout.write("\033[F")
print (name, "said:", say)

Code on 3rd line moves cursor up one line.

Upvotes: 1

Related Questions