On this page
  1. os.getenv
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

os.getenv

Prev: os.getcwd | Up: os | Next: os.getpid
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.getenv
Tags: #public #python3 #stdlib #os


Import

import os
from os import getenv

Signature & Overview

os.getenv(key, default=None)

Get an environment variable, return None if it doesn't exist.

Usage

import os

val = os.getenv("NONEXISTENT_DEMO_VAR_XYZ", "default_val")
assert val == "default_val"

Gotchas

REPL Inspect

from os import getenv
help(getenv)

Linked from

Related notes