Python switch between users

Issue

I am trying to implement a switch at the beginning of my code, in order to change the working directory based on who’s running the code. In Stata, this exists and looks like the following:

if "`c(username)'" == "albert" { 
    local PATH "/home/albert/Dropbox/Project1"
} 
else if "`c(username)'" == "charlene" {
    local PATH "C:/Users/charlene/Documents/Dropbox/Project1"
}

I am just missing the "user" part in pyhton. Does anyone knows if that even exists ?

Solution

Would the getpass.getuser() function do the trick?

Answered By – Jiří Baum

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published