getpass
— Portable password input便携式密码输入¶
Source code: Lib/getpass.py
The getpass
module provides two functions:getpass
模块提供两个功能:
-
getpass.
getpass
(prompt='Password: ', stream=None)¶ Prompt the user for a password without echoing.提示用户输入密码而不回显。The user is prompted using the string prompt, which defaults to使用字符串prompt提示用户,默认为'Password: '
.'Password: '
。On Unix, the prompt is written to the file-like object stream using the replace error handler if needed.在Unix上,如果需要,将使用替换错误处理程序将提示写入类似文件的对象stream。streamdefaults to the controlling terminal (默认为控制终端(/dev/tty
) or if that is unavailable tosys.stderr
(this argument is ignored on Windows)./dev/tty
),或者如果sys.stderr
不可用(在Windows上忽略此参数)。If echo free input is unavailable getpass() falls back to printing a warning message to stream and reading from如果无回声输入不可用,sys.stdin
and issuing aGetPassWarning
.getpass()
会返回到打印警告消息到流并从sys.stdin
读取并发出GetPassWarning
。Note
If you call getpass from within IDLE, the input may be done in the terminal you launched IDLE from rather than the idle window itself.如果从IDLE中调用getpass,则输入可能在启动IDLE的终端中完成,而不是在IDLE窗口本身中完成。
-
exception
getpass.
GetPassWarning
¶ A当可能回显密码输入时发出的UserWarning
subclass issued when password input may be echoed.UserWarning
子类。
-
getpass.
getuser
()¶ Return the “login name” of the user.返回用户的“登录名”。This function checks the environment variables此函数按顺序检查环境变量LOGNAME
,USER
,LNAME
andUSERNAME
, in order, and returns the value of the first one which is set to a non-empty string.LOGNAME
、USER
、LNAME
和USERNAME
,并返回设置为非空字符串的第一个变量的值。If none are set, the login name from the password database is returned on systems which support the如果未设置,则在支持pwd
module, otherwise, an exception is raised.pwd
模块的系统上返回密码数据库中的登录名,否则将引发异常。In general, this function should be preferred over通常,此函数应优先于os.getlogin()
.os.getlogin()
。