Skip to content

Instantly share code, notes, and snippets.

@CMWolfe922
Created November 30, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMWolfe922/7cab0cda7b438d22f5c47e4817b5a7ad to your computer and use it in GitHub Desktop.
Save CMWolfe922/7cab0cda7b438d22f5c47e4817b5a7ad to your computer and use it in GitHub Desktop.
environment variables
import os
# Set environment variables
os.environ['API_USER'] = 'username'
os.environ['API_PASSWORD'] = 'secret'
# Get environment variables
USER = os.getenv('API_USER')
PASSWORD = os.environ.get('API_PASSWORD')
# Getting non-existent keys
FOO = os.getenv('FOO') # None
BAR = os.environ.get('BAR') # None
BAZ = os.environ['BAZ'] # KeyError: key does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment