I've recently come across functionality that does not seem to be currently implemented in python.
Currently we can obtain the active user's folder in several ways (speaking of linux):
import os os.environ("HOME") os.path.expanduser("~/")
But what if our script has been called with sudo?
$sudo python my_script.py import os print(os.environ["HOME"]) => /root print(os.path.expanduser("~/")) => /root/ print(os.geteuid()) => 0 print(os.getenv("HOME")) => /root print(os.getenv("USER")) => root print(os.getenv("SUDO_UID")) => 1000 print(os.getenv("SUDO_USER")) => dev
Before implementing my own function to obtain a user's folder, I would like to know if someone knows the most pythonic form or if someone has already implemented it.