Is there a portable way to get the current user\'s username in Python (i.e., one that works under both Linux and Windows, at least). It would work like os.getuid
os.getuid
You best bet would be to combine os.getuid() with pwd.getpwuid():
os.getuid()
pwd.getpwuid()
import os import pwd def get_username(): return pwd.getpwuid( os.getuid() )[ 0 ]
Refer to the pwd docs for more details:
http://docs.python.org/library/pwd.html