Can i get console input without echo in python?

Python

Python Problem Overview


Can I get console input without echo in python?

Python Solutions


Solution 1 - Python

Use getpass:

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

Solution 2 - Python

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"

Solution 3 - Python

Maybe the ['console'][1] 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.

[1]: http://effbot.org/zone/console-handbook.htm "console module"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser181351View Question on Stackoverflow
Solution 1 - PythonJosh LeeView Answer on Stackoverflow
Solution 2 - PythonMichaelView Answer on Stackoverflow
Solution 3 - PythonmguillechView Answer on Stackoverflow