How to fetch environment variables in Mac OS X using python?

Afiku picture Afiku · Jan 26, 2011 · Viewed 8.2k times · Source

How can I lookup environment variables (e.g. export HG_USER from .profile) using python code in Mac OS X?

Answer

Vlad H picture Vlad H · Jan 26, 2011

os.environ is a dictionary containing all the environment variables. You need to import os before you can use it. So, for example HG_USER would be accessed by os.environ['HG_USER'].