2

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
  • 10,905
  • 5
  • 18
  • 32
hypnoz
  • 23
  • 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,138
  • 9
  • 46
  • 52
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
  • 17,267
  • 17
  • 78
  • 79