- os.environ
Accessing the system environment variables from Python
examples/os/environment.py
import os print(os.environ['HOME']) # /Users/gabor print(os.environ.get('HOME')) # /Users/gabor for k in os.environ.keys(): print("{:30} {}".format(k , os.environ[k]))
os.environ is a dictionary where the keys are the environment variables and the values are, well, the values.