3

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

2
  • Replace say = input("Say: ") with say = input() Commented Jun 3, 2014 at 18:30
  • This is not possible. See this answer. Commented Jun 3, 2014 at 18:32

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Code on 3rd line moves cursor up one line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.