2

What is a "pythonic" way to determine which user ran a python script from within the script?

For instance, I know that you can run shell commands from within the script to do an

echo $USER

but is there a more standard python way of determining which user is running the script?

Like a get_user() command for a standard library?

user1431282
  • 6,535
  • 13
  • 51
  • 68
  • 2
    http://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python – Frodon Jul 19 '13 at 01:28

2 Answers2

2

As noted in my comment, the answer is given here: https://stackoverflow.com/a/842096/2531279

Note: this is available for Windows and Unix

Community
  • 1
  • 1
Frodon
  • 3,684
  • 1
  • 16
  • 33
0

Wouldn't it depend on what OS you are running the script on? Running shell commands is more common on some flavor of Linux but it could be a windows or Mac machine. Python may have a way of doing that cross platform, i'm not sure.

Ryan Cori
  • 460
  • 1
  • 3
  • 11