getting the current userid with Python

Gerhard Häring gerhard.haering at opus-gmbh.net
Wed Aug 21 19:55:37 CEST 2002


In article <2f177cd8.0208210938.2c166943 at posting.google.com>, Danathar wrote:
> Is there a direct method for getting the current userid in Python? I
> am learning Python for the first time and was looking around for
> methods, but the only methods that I can find in usenet usually call
> external commands with the commands module or use the os module to get
> the value of of the USER shell environment variable.
> 
> Those methods work, but I am trying to learn python, and somehow it
> feels like I am cheeting by using python to call a shell command (like
> whoami) that I already know. Getting the USER variable works, but what
> if you are not in a UNIX envornment where the USER variable does not
> exist?
> 
> I've looked through the books, but I can't find anything...
> 
> thanks for any suggestions?

On professional Windows flavours, there's a USERNAME environment variable.
-- 
Gerhard Häring
OPUS GmbH München
Tel.: +49 89 - 889 49 7 - 32
http://www.opus-gmbh.net/



More information about the Python-list mailing list