python - 有没有简单的方法来防止输入回声?

标签 python python-3.x

如何防止输入回声?

尝试过“getpass()”但没有成功。

在 Windows IDLE 上,它不起作用

    Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import getpass
>>> p = getpass.getpass(prompt="Input: ")
Warning: Password input may be echoed.
Input: abc <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< It still echos..

在Windows终端上,它可以工作

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass
>>> p = getpass.getpass(prompt="Input: ")
Input:
>>>

有没有简单的方法来防止输入回声?

最佳答案

我假设你的第一个例子是在 IDLE 中。

来自 getpass.win_getpass():

if sys.stdin is not sys.__stdin__:
    return fallback_getpass(prompt, stream)

IDLE 将 sys.stdin 替换为不同的对象。 getpass 检测到有人包装了 stdin,并且由于安全原因而失败。

参见:http://bugs.python.org/issue9290

关于python - 有没有简单的方法来防止输入回声?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17520292/

相关文章:

python - Leetcode 424.最长重复字符替换: Right Pointer Incrementation

python - 如何将 lineedit 中的内容插入到 MySQL 中?

python - 为什么这个附加程序是错误的——使用 Pandas?

python-3.x - 尽管 xxx 是全局定义的,但预期的 NameError : name 'xxx' is not defined

python - 内部类 - 继承和覆盖它们的属性

Python设置小数精度

python - DLL 加载失败 : The specified module could not be found

python - Pandas 像嵌套的 countifs 一样出色

python - `asyncio.sleep(delay)` 是否保证至少休眠 `delay` 秒?

Python 在字符串列表中的搜索模式