import os import yaml import os.path as osp def get_config(dir): # add direction join function when parse the yaml file def join(loader, node): seq = loader.construct_sequence(node) return os.path.sep.join(seq) # add string concatenation function when parse the yaml file def concat(loader, node): seq = loader.construct_sequence(node) return ''.join(seq) yaml.add_constructor('!join', join) yaml.add_constructor('!concat', concat) with open(dir, 'r') as f: cfg = yaml.load(f) return cfg def check_dir(folder): if not osp.exists(folder): os.mkdir(folder)