eis/py/comlib/file/ConfigUtil.py

40 lines
1.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
'''
* @Author : zoufuzhou
* @Date : 2024-07-05 16:34:37
* @Description : read ini config file
* @LastEditTime : 2024-07-05 16:34:37
'''
import configparser
from PathUtil import PathUtil
class ConfigUtil:
# 创建ConfigParser对象
config = configparser.ConfigParser()
def __init__(self):
self.path = PathUtil().getPathConfig()
# print(self.path)
def load(self, file):
self.config.read(self.path+file, encoding='UTF-8')
# with open(self.path+file, encoding='utf-8') as f:
# self.config.read_file(f)
# print(self.path+file)
def getProperties(self, section, key):
# 获取特定section中的值
return self.config.get(section, key)
def getSection(self, section):
# 获取特定section中的所有选项和值
return dict(self.config.items(section))
# return self.config.options(section)
# cfg = ConfigUtil()
# cfg.load('crgs.cfg1')
# section = cfg.getSection('db')
# for it in section:
# print(it)