2019-03-01
阅读量:
563
python如何录入用户名
python用于录入用户名的函数主要是getpass.getuser(),getuser()函数显示用户的登录名。此函数按顺序检查环境变量LOGNAME,USER,LNAME和USERNAME,并返回第一个非空字符串的值。
示例代码:
# Python program to demonstrate working of
# getpass.getuser()
import getpass
user = getpass.getuser()
while True:
pwd = getpass.getpass("User Name : %s" % user)
if pwd == 'abcd':
print "Welcome!!!"
break
else:
print "The password you entered is incorrect."
输出 :
$ python3 getpass_example3.py
User Name : bot
Welcome!!!
$ python3 getpass_example3.py
User Name : bot
The password you entered is incorrect.






评论(0)


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