Question

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:)

Was it helpful?

Solution

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.

OTHER TIPS

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

Code on 3rd line moves cursor up one line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top