#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 配置管理器 Configuration Manager """ from configparser import ConfigParser import os class ConfigHandler: def __init__(self, config_file=None): self.config = ConfigParser() if os.path.exists(config_file): self.config.read(config_file, encoding='utf-8') # @staticmethod def get(self, section, option, default=None): try: value = self.config.get(section, option) if "#" in value: value = value.split('#')[0].strip() except Exception: value = default return value # 全局配置实例 config_handler = ConfigHandler("./config/config.ini")