Definition
Dynamic-named values stored by the operating system that can affect the way running processes behave on a computer.
Why It Matters
Environment variables allow a program to remain context-aware and portable without hardcoding system-specific details like file paths or API keys. They are the essential “externalized configuration” that decouples your code’s logic from the specific machine it’s running on, enabling scalable and secure automation.
Core Concepts
import os
# Reading an environment variable
path = os.environ.get('PATH')
print(f"System PATH: {path}")
# Setting a custom variable (for current process)
os.environ['MY_APP_MODE'] = 'production'
PATH: The most critical variable for automation. It tells the OS which folders to search for executable files (likepython.exeor your own.batscripts).PYTHONPATH: Tells the Python interpreter where to look for modules to import, in addition to the standard library and site-packages.- Interaction: Python can read these variables via the
os.environdictionary.