Read an environment variable

EasyOS Module Programs · 2 of 49

Write a Python program to read an environment variable.

Advertisement
Output
True
development

Approach

  1. os.environ.get(name, default) or os.getenv(name, default).

Solution

Python
import os print("PATH" in os.environ)print(os.getenv("APP_MODE", "development"))
Output
True
development

Line by line

Line 4

APP_MODE is not set, so the default is returned instead of an error.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs