jetz
7/9/2014 - 6:47 AM

Python config with YAML

Python config with YAML

import os
import yaml

ROOT = os.path.split(os.path.realpath(__file__))[0]


class Struct(object):

    def __init__(self, **entries):
        self.__dict__.update(entries)

with open(os.path.join(ROOT, 'config.yaml'), 'r') as f:
    confs = yaml.safe_load(f)
    cfg = Struct(**confs)
    cfg.ROOT = ROOT