python中getpass模块

1.getpass

1 import getpass
2 username = input("username:")
3 password = getpass.getpass("password:")
4 print(username,password)

在pycharm中运行下面的代码时不能输入密码(软件问题,代码没错),选择命令行执行

python中getpass模块_第1张图片

密码默认不显示

 

例子:

 1 import getpass
 2 _usename = "fww"
 3 _password = "123"
 4 username = input("username:")
 5 password = getpass.getpass("password:")
 6 print(username,password)
 7 if _usename == username and _password == password:
 8     print("Welcome user {name} login".format(name = username))
 9 else:
10print("Invalid username or password")

结果显示

python中getpass模块_第2张图片

 

你可能感兴趣的:(python中getpass模块)