Return the "login name" of the user.
This function checks the environment variables :envvar:`LOGNAME`,
- :envvar:`USER`, :envvar:`LNAME` and :envvar:`USERNAME`, in order, and returns
- the value of the first one which is set to a non-empty string. If none are set,
- the login name from the password database is returned on systems which support
- the :mod:`pwd` module, otherwise, an exception is raised.
+ :envvar:`USER`, :envvar:`LNAME` and :envvar:`USERNAME`, in order, and
+ returns the value of the first one which is set to a non-empty string. If
+ none are set, the login name from the password database is returned on
+ systems which support the :mod:`pwd` module, otherwise, an exception is
+ raised.
+ In general, this function should be preferred over :func:`os.getlogin()`.
.. function:: getlogin()
Return the name of the user logged in on the controlling terminal of the
- process. For most purposes, it is more useful to use the environment
- variables :envvar:`LOGNAME` or :envvar:`USERNAME` to find out who the user
- is, or ``pwd.getpwuid(os.getuid())[0]`` to get the login name of the current
- real user id.
+ process. For most purposes, it is more useful to use
+ :func:`getpass.getuser` since the latter checks the environment variables
+ :envvar:`LOGNAME` or :envvar:`USERNAME` to find out who the user is, and
+ falls back to ``pwd.getpwuid(os.getuid())[0]`` to get the login name of the
+ current real user id.
Availability: Unix, Windows.