yamlUtil.py 748 Bytes
Newer Older
1 2 3
# -*- coding: utf-8 -*-
"""
@author:zhaiht
zhaihuitao committed
4
@file:  yamlUtil.py
5 6 7 8 9 10
@time:  2020/8/4 14:12
@desc:  analysis yaml
"""

import yaml

zhaihuitao committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

class loadYaml:
    def read_yaml(self, filepath):
        try:
            return yaml.load(open(filepath, 'r', encoding='utf-8'), Loader=yaml)
        except Exception as es:
            print(F'读取{filepath}文件出错,错误是{es}')
            return False

    def write_yaml(self, filepath, data, mode='w'):
        try:
            with open(filepath, mode, encoding='utf-8') as f:
                yaml.dump(data, f)
            return True
        except Exception as es:
            print(F'内容:{data}\n写入{filepath}文件出错,错误是{es}')
            return False
28 29

ly = loadYaml()