File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,8 +42,10 @@ The :mod:`getpass` module provides two functions:
4242 Return the "login name" of the user.
4343
4444 This function checks the environment variables :envvar: `LOGNAME `,
45- :envvar: `USER `, :envvar: `LNAME ` and :envvar: `USERNAME `, in order, and returns
46- the value of the first one which is set to a non-empty string. If none are set,
47- the login name from the password database is returned on systems which support
48- the :mod: `pwd ` module, otherwise, an exception is raised.
45+ :envvar: `USER `, :envvar: `LNAME ` and :envvar: `USERNAME `, in order, and
46+ returns the value of the first one which is set to a non-empty string. If
47+ none are set, the login name from the password database is returned on
48+ systems which support the :mod: `pwd ` module, otherwise, an exception is
49+ raised.
4950
51+ In general, this function should be preferred over :func: `os.getlogin() `.
Original file line number Diff line number Diff line change @@ -325,10 +325,11 @@ process and user.
325325.. function :: getlogin()
326326
327327 Return the name of the user logged in on the controlling terminal of the
328- process. For most purposes, it is more useful to use the environment
329- variables :envvar: `LOGNAME ` or :envvar: `USERNAME ` to find out who the user
330- is, or ``pwd.getpwuid(os.getuid())[0] `` to get the login name of the current
331- real user id.
328+ process. For most purposes, it is more useful to use
329+ :func: `getpass.getuser ` since the latter checks the environment variables
330+ :envvar: `LOGNAME ` or :envvar: `USERNAME ` to find out who the user is, and
331+ falls back to ``pwd.getpwuid(os.getuid())[0] `` to get the login name of the
332+ current real user id.
332333
333334 Availability: Unix, Windows.
334335
You can’t perform that action at this time.
0 commit comments