yaml相关方法封装
读取指定yaml文件数据
import yaml import sys,os add_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(add_path) path = os.path.dirname(__file__) yaml_path =path + '/xxxx.yaml' def read_file_data_yaml(yaml_path,hierarchy=None): ''' :param yaml_path: 打开的yaml文件夹路径 :param hierarchy: 二级层级,没有则打开一级路径数据 :return: ''' with open(yaml_path,'rb') as f :# 传入文件路径 config = yaml.load(stream=f, Loader=yaml.FullLoader) if hierarchy: yaml_data = config[hierarchy] else: yaml_data = config return yaml_data