Can i get console input without echo in python?

Question:

Can I get console input without echo in python?

Asked By: user181351

||

Answers:

Use getpass:

>>> from getpass import getpass
>>> getpass()
Password:
'secret'
Answered By: Josh Lee

Maybe the ‘console’ module is your only bet (it’s kinda ‘fork’ of the curses module for Unix), however I haven’t seen anything related to terminal echo disabling in its homepage, you might try to dig into it by yourself.

Answered By: mguillech

There is also another solution (at least on unix systems, I don’t know if this is working on Windows). Simply switch off the console output and use raw_input:

os.system("stty -echo")
password = raw_input('Enter Password:')
os.system("stty echo")
print "n"
Answered By: Michael
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.