Last active
January 30, 2018 09:59
-
-
Save bmwant/8e470c0b6848cf825a978cdfabcf8896 to your computer and use it in GitHub Desktop.
Override config values from environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
KEY1 = 'VALUE1' | |
KEY2 = 'VALUE2' | |
# Override values from config_local.py if exists | |
try: | |
import config_local | |
for key, value in config_local.__dict__.items(): | |
if key.isupper() and key in globals(): | |
globals()[key] = value | |
except ImportError: | |
pass | |
# Override values from environment | |
for key, value in globals().copy().items(): | |
if key.isupper() and key in os.environ: | |
globals()[key] = os.environ[key] | |
# export KEY2='NEWVALUE2' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment