Skip to content

Instantly share code, notes, and snippets.

@akkefa
Created December 11, 2017 09:18
Show Gist options
  • Save akkefa/46ba3528eaa9d5e1b09496bcdd996545 to your computer and use it in GitHub Desktop.
Save akkefa/46ba3528eaa9d5e1b09496bcdd996545 to your computer and use it in GitHub Desktop.
import os
print os.environ['HOME']
# Or you can see a list of all the environment variables using:
os.environ
#As sometimes you might need to see a complete list!
# using get will return `None` if a key is not present rather than raise a `KeyError`
print os.environ.get('KEY_THAT_MIGHT_EXIST')
# os.getenv is equivalent, and can also give a default value instead of `None`
print os.getenv('KEY_THAT_MIGHT_EXIST', default_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment