import yaml


class Cfg(dict):
    def __init__(self, config_dict):
        super(Cfg, self).__init__(**config_dict)
        self.__dict__ = self

    @staticmethod
    def load_config_from_file(fname):
        with open(fname, encoding="utf-8") as f:
            config = yaml.safe_load(f)
        return Cfg(config)

    def save(self, fname):
        with open(fname, "w") as outfile:
            yaml.dump(dict(self), outfile, default_flow_style=False, allow_unicode=True)
