#! /usr/bin/env python
# -*- coding:utf-8 -*-
# login 模块中登录时输入密码,想用getPass模块实现密码的不回显操作。
#如下:
import getpass ret = input("welcome to the system:please make a choice-1 or 2") if ret == '1': user = input("请输入用户名:") pwd = getpass.getpass("请输入密码:")
#结果:
#在pycharm中根本不起作用,用官方带的IDLE显示如下:
"""
welcome to the system:please make a choice-1 or 21
请输入用户名:wuwuwu
Warning (from warnings module):
File "C:Program FilesPython36libgetpass.py", line 100
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
请输入密码:123456
用户名不存在
>>>
"""
# 命令行界面中测试可行,getpass模块只能用于命令行界面!
# stack overflow 上 有大神如是说:
"""
Use an actual terminal -- that is, an environment where stdin,
stdout and stderr are connected to /dev/tty, or another PTY-compliant device.
The IDLE REPL does not meet this requirement.
"""