uname = getUserName()
I'm looking for a function to figure out the user name in this way.
I looked it up
os.getuid
works only on UNIX (and returns id, not name)
pwd
module is only available on Unix.
I hope it's a function that can be used on all platforms, but if not, at least it's a function that supports Linux and Windows at the same time.
python portability username
You can use getpass module with getpass.getuser()/a>. Can be used in Unix and Windows environments.
This function returns the user's login name
.
The login name is based on the first non-empty string (""
) of the environment variables LOGNAME
, USER
, LNAME
.
© 2024 OneMinuteCode. All rights reserved.