Skip to content

Instantly share code, notes, and snippets.

@nandyne
Created October 18, 2018 17:48
Show Gist options
  • Select an option

  • Save nandyne/5ff11254d8f28d4e06c09ea60235d7e8 to your computer and use it in GitHub Desktop.

Select an option

Save nandyne/5ff11254d8f28d4e06c09ea60235d7e8 to your computer and use it in GitHub Desktop.
yaml Config Loader
class _Config_Loader:
"""
Loads the Config file given while instantiating
"""
def __init__(self, config_path):
from utility.exceptions import ImproperlyConfigured
from pathlib import Path
import yaml
__config_path = Path(config_path).resolve()
print('Loading Config from file %s' % __config_path)
try:
with open(__config_path, 'r') as yaml_config_file:
self.config = yaml.safe_load(yaml_config_file)
except (yaml.YAMLError, yaml.MarkedYAMLError) as e:
raise ImproperlyConfigured(
"Your settings file(s) contain invalid YAML syntax! Please fix and restart!\n" +
repr(e))
config = _Config_Loader('config.yaml').config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment