get the user name

Steve Holden sholden at holdenweb.com
Thu Oct 25 06:58:34 EDT 2001


"anthony harel" <anthony.harel at c-s.fr> wrote ...
> Hi,
>
> Is there a way with python1.5.2 to get the name of the user on
> UNIX and Windows ?
>
>From Python 2.0 library reference manual, Section 6.11 (the getpass module):

"""
getuser ()
Return the ``login name'' of the user. Availability: Unix, Windows.
This function checks the environment variables $LOGNAME, $USER, $LNAME and
$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 pwd module, otherwise, an
exception is raised.
"""

So you are looking for getpass.getuser().

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list