eis/py/comlib/file/ConfigUtil_extended.py

46 lines
1.2 KiB
Python

# -*- 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 configparser_extended import ExtendedConfigParser
from PathUtil import PathUtil
class ConfigUtil:
# 创建ConfigParser对象
# config = configparser.ConfigParser()
config = ExtendedConfigParser()
def __init__(self):
self.path = self.path = PathUtil().getPathConfig()
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 getPath(self):
return self.path
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.cfg')
# section = cfg.getSection('db')
# for it in section:
# print(it)