Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python env variable

import os
# Preferred - no KeyError exceptions even if no default value given
os.getenv('KEY', 'default value')
# Alternate - NOTE: KeyError exception If a key is NOT present
os.environ['KEY']
# To avoid KeyError exceptions when using os.environ :
os.environ.get('KEY_THAT_MIGHT_EXIST') # Returns `None` if key doesn't exist
os.environ.get('KEY_THAT_MIGHT_EXIST', default_value) # Returns `default_value` if key doesn't exist
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #env #variable
ADD COMMENT
Topic
Name
2+6 =