[Python-Dev] Missing POSIX functions: the list

Guido van Rossum guido@CNRI.Reston.VA.US
Thu, 09 Dec 1999 12:16:03 -0500


> > getlogin() -- returns user's login name
> > 	 -- could do something similar with pwd.getpwuid( os.getuid() )[0], but
> > 	 getlogin() apparently looks in utmp
> 
> With a documentation proviso that utmp is very old-fashioned, and you
> really should do the getuid() thing unless you definitely want to get
> the login ID from utmp.  Perhaps an alternate "getlogin" (different
> name?) that does the getuid() thing could be provided.

There's the getpass module which has a getuser() function that looks
in various env vars and if all else fails uses getuid() and pwd.

If the goal is to get the user ID without being fooled, using
os.getuid() or os.geteuid() directly seems to be the right thing to
do; I don't see the need for a shorthand for
pwd.getpwuid(os.getuid())[0] (which is what getuser() uses).

--Guido van Rossum (home page: http://www.python.org/~guido/)