I am looking for an example of an instance where we import the Python getpass library, enter our password, and the password does not echo to the terminal.

Here is an example where it does echo the password to the terminal:

$ python
>>> import getpass
>>> getpass.GetPassWarning
<class 'getpass.GetPassWarning'>
>>> getpass.getpass(stream=None)
Password:
'hello'
>>> 

Can someone give an example where it does not echo to the terminal?

Thanks!

有帮助吗?

解决方案

You should write or save the password to a variable. Then the password will not be echoed. for example:

import getpass                                                                       

p=getpass.getpass("Enter the Password:")

Enter the Password:

print (p)

Output on console: pass@123

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top