read_ini.py
#coding=utf-8
import os
import configparser
import json
os.chdir("E:\py")
cf = configparser.ConfigParser()
cf.read("test.ini", encoding='utf-8-sig')
print(cf['db']['db_port'])
dic = {}
secs = cf.sections()
print(secs)
for sec in secs:
opts = cf.items("%s" %sec)
print(opts)
# indic = {}
# for i in opts:
# indic[i[0]] = i[1]
dic[sec] = dict(opts)
print(dic)
a = [1,2,3,4]
b = ['ab','ac','ad']
d = ['fa','fb','fc','fd','fe']
print(dict(zip(a,d)))
###################### test.ini ###########################
[db]
db_port = 3306
db_user = root
db_host = 127.0.0.1
db_pass = xgmtest
[concurrent]
processor = 20中文
thread = 10
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步