热线电话:13121318867

登录
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.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子