Reputation: 733
I have to type in a terminal a user password. googling arround lead to getpass
as the most recommended way to do it.
But, somehow- using this function did not hide the characters as expected. First I thought it has somthing to do with the platform ( Pycharm ), but testing is on IDLE yield the same.
any ideas why ? (code below was on Mac using Python shell)
>> import getpass
>>> a=getpass.getpass(prompt='Password')
Warning: Password input may be echoed.
PasswordTHISISPASSWORD
Upvotes: 1
Views: 5336
Reputation: 41
In the latest version of Pycharm, all you have to do is update your run configurations.
Run> Edit Configurations> Enable "Emulate terminal in output console"
This enables your Pycharm output console to behave as the terminal. Then, the getpass() function works well without echoing your password.
Upvotes: 3
Reputation: 106
I tried your code with a terminal and with PyCharm too, it works better in terminal but i found a checkbox in the run configurations of PyCharm that avoid the echoing of the password and set it correctly to the variable as you could see with the debugger, but i noticed that if you try to print the variable in some cases it prints something strange.
Click on Edit Configurations... on the left of the run button and check Emulate terminal in output console, it worked with the last version of PyCharm
EDIT: I read just now that you are using a Mac, I tried this with linux, so I'm not sure it will work on mac
Upvotes: 3
Reputation: 1445
if you will launch it from IDE it will cause echo will be seen. You can try it in command line terminal it works fine as can be seen in the attached screenshot.
hope this helps
Upvotes: 3