# coding:utf-8
import configparser
import os
import json

base_path = os.path.dirname(os.path.abspath(__file__))
conf_file= os.path.join(base_path,"config.ini")


def read_config():
    #读取配置文件信息
    try:
        cf=configparser.ConfigParser()
        cf.read(conf_file,encoding="utf-8")
        section_data=dict()
        for section in cf.sections():
            section_data[section] ={}
            for k,v in cf.items(section):
                section_data[section][k] = v
        return section_data
    except Exception as e:
        print("读取配置文件[{}]异常:{}".format(conf_file,e))
        return {}
    
if __name__ == "__main__":
    print(json.dumps(read_config(),indent=" "))

 

 posted on 2023-06-16 15:14  boye169  阅读(19)  评论(0)    收藏  举报