Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i get console input without echo in python?

Tags:

python

People also ask

How do you get the console input in Python?

The Python Console accepts commands in Python that you write after the prompt. Accepting Input from Console User enters the values in the Console and that value is then used in the program as it was required. To take input from the user we make use of a built-in function input().

How do you get input from the user without entering Python?

getch: Read a keypress and return the resulting character. Nothing is echoed to the console. This call will block if a keypress is not already available, but will not wait for Enter to be pressed.

How do you manually input in Python?

There are two functions that can be used to read data or input from the user in python: raw_input() and input(). The results can be stored into a variable. raw_input() – It reads the input or command and returns a string. input() – Reads the input and returns a python type like list, tuple, int, etc.


Use getpass:

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

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"