Skip to content

Instantly share code, notes, and snippets.

@murarisumit
Last active May 4, 2019 01:37
Show Gist options
  • Save murarisumit/edcd8bf361e6060ee41dc82311b23b83 to your computer and use it in GitHub Desktop.
Save murarisumit/edcd8bf361e6060ee41dc82311b23b83 to your computer and use it in GitHub Desktop.
Python configparser example #python
# 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