yaml文件
读取Yaml文件
import yaml class YamlUtil: def __init__(self, yaml_file): """ 通过init方法把Yaml文件传入到这个类 :param yaml_file: """ self.yaml_file = yaml_file # 读取Yaml文件 def read_yaml(self): """ 读取Yaml,对yaml反序列化,就是把我们的yaml格式转换成dict格式 :return: """ with open(self.yaml_file, encoding='utf-8')as f: value = yaml.load(f, Loader=yaml.FullLoader) print(value) if __name__ == '__main__': YamlUtil('test_api.yaml').read_yaml()
运行结果:
标签:__,文件,读取,Yaml,self,yaml,file From: https://www.cnblogs.com/may18/p/17704246.html