Python reads the configuration file Error: configparser.nosectionerror: no section: ‘MySQL’

import configparser

class ReadConfig:
    """Define a class that reads configuration files """

    def __init__(self):
        configpath = "absolute path to the config.ini file"
        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)

Change configpath to absolute path

Similar Posts: