【问题标题】:Python getpass example where password is not echoed to the terminalPython getpass 示例,其中密码未回显到终端
【发布时间】:2014-04-18 18:40:16
【问题描述】:

我正在寻找我们导入 Python getpass 库,输入我们的密码,并且密码不会回显到终端的实例的示例。

这是一个将密码回显到终端的示例:

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

有人可以举一个不回显到终端的例子吗?

谢谢!

【问题讨论】:

  • 您必须指定值:my_pwd = getpass.getpass(stream=None)
  • 谢谢!!!像魅力一样工作!

标签: python passwords


【解决方案1】:

您应该将密码写入或保存到变量中。那么密码将不会被回显。 例如:

import getpass                                                                       

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

Enter the Password:

print (p)

Output on console: 通过@123

【讨论】:

    猜你喜欢
    • 2013-03-18
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 2012-11-21
    • 2022-08-18
    • 1970-01-01
    相关资源
    最近更新 更多