0Pricing
Python Academy · Lesson

Environment and os Module

Read env vars and paths.

The os Module

The os module is your gateway to the operating system: environment variables, file paths, the current directory, and process info.

import os

print('os name:', os.name)

Reading Environment Variables

os.environ is a dict-like mapping of environment variables. Index it to read a value.

import os

os.environ['MY_APP_MODE'] = 'demo'
print(os.environ['MY_APP_MODE'])

All lessons in this course

  1. Running Commands with subprocess
  2. Capturing Output
  3. Environment and os Module
  4. shutil for File Operations
← Back to Python Academy