user181351
user181351

Reputation:

Can I get console input without echo in Python?

Can I get console input without echo in Python?

Upvotes: 58

Views: 42090

Answers (3)

mguillech
mguillech

Reputation: 336

Maybe the 'console' module is your only bet (it's kind of a '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.

Upvotes: 0

Michael
Michael

Reputation: 127

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"

Upvotes: 11

Josh Lee
Josh Lee

Reputation: 177554

Use getpass:

>>> from getpass import getpass
>>> getpass()
Password:
'secret'

Upvotes: 81

Related Questions