Thanks Alan (and Mats)!  It appears there are many ways to skin this cat!

On Sat, Aug 26, 2017 at 2:21 AM, Alan Gauld via Tutor <tutor@python.org> wrote:
>
>> My objective:  Determine who the currently logged in user is and
>> determine if that user is in my list of users that I have authorized
>> to use my programs.
>
> In addition to Steve and Mats answers:
>
> import os
> os.getlogin()   #-> 'alan'
> os.getuid() #-> 1001
>
> import pwd
> pwd.getpwuid(os.getuid()) #-> loads of user related stuff...
>
> You can also use the environment variables such as
>
> os.getenv('USER') #-> 'alan'
> os.getenv('HOME') #-> '/home/alan'
>
> the latter being a useful place to look for the
> individual config file... You can use os.environ
> if you prefer a dictionary style to a function.
>
> And of course
>
> os.cwd() #-> '/home/alan'
>
> For the current directory.


-- 
boB
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to