yaml文件读取

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)
return value
if __name__ == '__main__': YamlUtil('test_api.yaml').read_yaml()

运行结果:

 =====================================

- msxy: case0
  name: case
- aa: haha1

 ===================================

yaml数据如下:

filename: C://Users//YM520//Desktop//caseqq.xlsx
sheetname: case

 ==========================

yaml数据如下时:

- filename: C://Users//YM520//Desktop//caseqq.xlsx
- sheetname: case

 

运行结果:

 

posted @ 2023-09-15 10:11  yimu-yimu  阅读(63)  评论(0编辑  收藏  举报