Custom Search

Tuesday, April 12, 2011

python how to get current username windows linux

python how to get current username windows linux

import os
user_name = os.getusername()

------------------OR

import getpass
user_name = getpass.getuser()

------------------OR

Combine os.getuid() with pwd.getpwuid().

import os
import pwd
user_name = pwd.getpwuid( os.getuid() )[ 0 ]


http://docs.python.org/library/pwd.html

------------------OR

import os
user_name = os.getlogin()

No comments:

Post a Comment