eis/py/comlib/file/ConfigYaml.py

37 lines
766 B
Python

# -*- coding: utf-8 -*-
'''
* @Author : zoufuzhou
* @Date : 2024-03-14 16:34:37
* @Description : read yaml config file
* @LastEditTime : 2024-03-14 16:34:37
'''
import yaml
from file.PathUtil import PathUtil
class ConfigYaml:
def __init__(self):
self.path = PathUtil().getPathConfig()
# print(self.path)
def load(self, file):
with open(self.path+file, 'r') as f:
self.yamlcfg = yaml.safe_load(f)
# print(self.jsoncfg)
def getPath(self):
return self.path
def getProperties(self, key):
# 获取特定section中的值
return self.yamlcfg[key]
# cfg = ConfigYaml()
# cfg.load('config.yaml')
# data = cfg.getProperties('mysql')
# for it in data:
# print(it)