2019-03-01
阅读量:
635
python如何录入密码?
python中提供了一个录入密码的函数:getpass()函数提供了一种安全的方法来处理程序通过终端与用户交互的密码提示。
以下是该函数的参数说明
getpass()
getpass.getpass(prompt='Password: ', stream=None)
getpass()函数用于使用字符串提示提示用户,并将用户的输入作为密码读取。输入读取deafults到“Password:”作为字符串返回给调用者。
示例代码:
# A simple Python program to demonstrate
# getpass.getpass() to read password
import getpass
try:
p = getpass.getpass()
except Exception as error:
print('ERROR', error)
else:
print('Password entered:', p)
这里,调用者没有提供提示。因此,它被设置为默认提示“密码”。
输出 :
$ python3 getpass_example1.py
Password:
('Password entered:', 'aditi')






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论