
import configparser
from config.config import Config


class ReadConfig(object):
    def __init__(self):
        # 获取ini配置文件解析器
        self.config = configparser.RawConfigParser()
        # 获取ini配置文件路径
        self.ini_path = Config().ini_path
        # 读取ini配置文件
        self.config.read(self.ini_path, encoding='utf-8')

    """通过section与option获取ini文件的值"""

    def get(self, section, option):
        return self.config.get(section, option)

    """将段下面的数据项更新"""

    def set(self, section, option, value):
        self.config.set(section, option, value)
        with open(self.ini_path, 'w') as w:
            self.config.write(w)
