import configparser class ConfigUtil: # 初始化ConfigParser对象 config = configparser.ConfigParser() def __init__(self,path:str): # 读取并加载配置文件config.ini self.config.read(path,encoding="utf-8") def get(self, section: str, key: str) -> str: """ 获取配置项的字符串值 参数: section (str): 配置文件中的节名 key (str): 节中的配置项键名 返回: str: 配置项的字符串值 """ return self.config.get(section, key) def getBool(self, section: str, key: str) -> bool: """ 获取配置项的布尔值 参数: section (str): 配置文件中的节名 key (str): 节中的配置项键名 返回: bool: 配置项的布尔值 """ return self.config.getboolean(section, key) def getInt(self, section: str, key: str) -> int: """ 获取配置项的整数值 参数: section (str): 配置文件中的节名 key (str): 节中的配置项键名 返回: int: 配置项的整数值 """ return self.config.getint(section, key) def getFloat(self, section: str, key: str) -> float: """ 获取配置项的浮点数值 参数: section (str): 配置文件中的节名 key (str): 节中的配置项键名 返回: float: 配置项的浮点数值 """ return self.config.getfloat(section, key) def getSectionList(self) -> list: """ 获取配置文件中的所有节名 返回: list: 所有节名的列表 """ return self.config.sections() def getKeyList(self, section: str) -> list: """ 获取指定节中的所有键名 参数: section (str): 配置文件中的节名 返回: list: 指定节中的所有键名的列表 """ return self.config.options(section)