Last active
May 4, 2019 01:37
-
-
Save murarisumit/edcd8bf361e6060ee41dc82311b23b83 to your computer and use it in GitHub Desktop.
Python configparser example #python
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
# definations.py | |
import os | |
import configparser | |
# Environment defination variable, this environment variable will use used to pick config file | |
ENV = os.environ["ENVIRONMENT"] | |
# settings | |
settings = configparser.ConfigParser() | |
BASEDIR = os.path.dirname(os.path.realpath(__file__)) | |
CONFIG_ROOT = os.path.join(BASEDIR, 'conf') | |
# Prod env: $ROOT/conf/production_config.ini | |
# Dev env: $ROOT/conf/dev_config.ini | |
CONFIG_FILE = os.path.join(CONFIG_ROOT, ENV + '_config.ini') | |
settings.read(CONFIG_FILE) | |
# file.py | |
import definations | |
settings = definations.settings | |
ENV = definations.ENV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment