Differences between revisions 1 and 2
Revision 1 as of 2023-04-25 02:02:08
Size: 496
Comment:
Revision 2 as of 2023-04-25 02:07:12
Size: 1158
Comment:
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
Get user input without printing to the screen.

{{{
import getpass

passwd = getpass.getpass(prompt='This is a prompt for your password: ')
}}}

The `prompt` anmed option defaults to `"Password: "`.

Internally the prompt is written to a file stream (`/dev/tty` by default, or `sys.stderr` if that is unavailable). This can be configured with the `stream` named option ''except on [[Windows]]''.

If a non-printing stream cannot be located, `getpass.getpass` falls back on `sys.stdin` and raises `getpass.GetPassWarning`.
Line 31: Line 45:
Returns the value of the first non-empty environment variable: `LOGNAME`, `USER`, `LNAME`, and `USERNAME`, in that order.

Python GetPass

getpass is a utility module for getting user input without printing to the screen.


Usage

GetPass

Get user input without printing to the screen.

import getpass

passwd = getpass.getpass(prompt='This is a prompt for your password: ')

The prompt anmed option defaults to "Password: ".

Internally the prompt is written to a file stream (/dev/tty by default, or sys.stderr if that is unavailable). This can be configured with the stream named option except on Windows.

If a non-printing stream cannot be located, getpass.getpass falls back on sys.stdin and raises getpass.GetPassWarning.


GetPassWarning

A UserWarning subclass that is raised when user input may be printed to the screen.


GetUser

Returns the value of the first non-empty environment variable: LOGNAME, USER, LNAME, and USERNAME, in that order.


See also

Python getpass module documentation


CategoryRicottone

Python/GetPass (last edited 2023-06-15 18:36:25 by DominicRicottone)