15.10. getpass — 便携式密码输入工具¶
getpass 模块提供了两个函数:
-
getpass.getpass([prompt[, stream]])¶ Prompt the user for a password without echoing. The user is prompted using the string prompt, which defaults to
'Password: '. On Unix, the prompt is written to the file-like object stream. stream defaults to the controlling terminal (/dev/tty) or if that is unavailable tosys.stderr(this argument is ignored on Windows).如果回显自由输入不可用则 getpass() 将回退为打印一条警告消息到 stream 并且从
sys.stdin读取同时发出GetPassWarning。在 2.5 版更改: The stream parameter was added.
在 2.6 版更改: On Unix it defaults to using /dev/tty before falling back to
sys.stdinandsys.stderr.注解
如果你从 IDLE 内部调用 getpass,输入可能是在你启动 IDLE 的终端中而非在 IDEL 窗口本身中完成。
-
exception
getpass.GetPassWarning¶ 一个当密码输入可能被回显时发出的
UserWarning子类。
