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



posted @   carlvine  阅读(193)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示