python getpass模块:隐藏不显示输入的密码

不知道为什么,本机测试必须要在debug模式下才正常运行。。

import getpass                                  #用于隐藏用户输入的字符串,常用来接收密码

def checkuser(user,passwd):
    if user == 'chenhang' and passwd == '123456':
        return True
    else:
        return False

if __name__ == "__main__":
    userr = input('Input the user:')
    passwdd = getpass.getpass('Input the passwd:')

    if checkuser(userr,passwdd):
        print('OK!')
    else:
        print('ERROR!')
原文地址:https://www.cnblogs.com/hanggegege/p/5751155.html