import os
from configparser import ConfigParser
classConfigDict(dict):"""
config.py
"""defload_config(self, filename):''' Load values from an *.ini style config file.
If the config file contains sections, their names are used as
namespaces for the values within. The two special sections
``DEFAULT`` and ``bottle`` refer to the root namespace (no prefix).
'''
conf = ConfigParser()
conf.read(filename)for section in conf.sections():for key, value in conf.items(section):if section notin('default','bottle'):
key = section +'.'+ key
#
self[key]= value
return self
config = ConfigDict()if __name__ =='__main__':
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),"conf.ini")
conf = config.load_config(config_file)print(conf.get("db_host"))print(conf["db_port"])print(conf.get("other.name"))print(conf["other.log_path"])