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

braX
  • 11,506
  • 5
  • 20
  • 33
hypnoz
  • 33
  • 1
  • 3

2 Answers2

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

Code on 3rd line moves cursor up one line.

pacholik
  • 8,607
  • 9
  • 43
  • 55
1

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.

julienc
  • 19,087
  • 17
  • 82
  • 82