Read password from stdin

Boldewyn picture Boldewyn · Nov 19, 2009 · Viewed 71.6k times · Source

Scenario: An interactive CLI Python program, that is in need for a password. That means also, there's no GUI solution possible.

In bash I could get a password read in without re-prompting it on screen via

read -s

Is there something similar for Python? I.e.,

password = raw_input('Password: ', dont_print_statement_back_to_screen)

Alternative: Replace the typed characters with '*' before sending them back to screen (aka browser' style).

Answer

mjv picture mjv · Nov 19, 2009
>>> import getpass
>>> pw = getpass.getpass()