Skip to content

Instantly share code, notes, and snippets.

@gaycookie
Last active April 14, 2020 12:53
Show Gist options
  • Save gaycookie/b0e285f0787dee15350a19d7d547b8cd to your computer and use it in GitHub Desktop.
Save gaycookie/b0e285f0787dee15350a19d7d547b8cd to your computer and use it in GitHub Desktop.
YAML ConfigParser
from yaml import safe_load, YAMLError
class ConfigParser:
def __init__(self, file_name):
self.config = self.__load(file_name)
def __load(self, file_name=''):
if len(file_name) == 0:
file_name = 'config.yaml'
with open(file_name, 'r') as stream:
try:
return safe_load(stream)
except YAMLError as exc:
print(exc)
def get(self):
return self.config
AppName: "ConfigParser"
from config import ConfigParser
Config = ConfigParser("config.yaml").get()
print(Config['AppName'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment