python读取配置文件报错提示ConfigParser.NoSectionError: No section: 'Mysql'

import configparser

class ReadConfig:
    """定义一个读取配置文件的类"""

    def __init__(self):
        configpath = "config.ini文件的绝对路径"
        self.cf = configparser.ConfigParser()
        self.cf.read(configpath)

    def get_db(self, param):
        value = self.cf.get("Mysql", param)
        return value


if __name__ == '__main__':
    test = ReadConfig()
    t = test.get_db("host")
    print(t)

将configpath修改为绝对路径

posted @ 2021-08-18 18:17  向前一步~  阅读(577)  评论(0编辑  收藏  举报