欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

getpass不起作用

程序员文章站 2022-03-07 22:41:31
...
#! /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 Files\Python36\lib\getpass.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.
"""