[Tutor] Getting Userid From System
Sean 'Shaleh' Perry
Thu, 24 Aug 2000 11:27:48 -0700
On Thu, Aug 24, 2000 at 12:31:10PM -0400, Perry, George W. wrote:
> Is there a module to obtain the current user name from the system? I.e. the
> unix userid or the Windows network logon ID.
print os.getuid() # only works on unix
I do not know of an easy way to get the Windows ID. There is a win32 module,
perhaps there is a windows call you can make? In python's OS and SYS module
there is a variable that allows you to check the OS you are running on.
if os.name == 'win':
user = win_getuid() # function you wrote
else: # this will bomb on mac and a few others, but as long as you dont care
user = os.getuid()
print "User is %s" % (user)