ini文件转换为Json文件

 1 '''
 2 ini文件转换为Json文件
 3 
 4 '''
 5 from configparser import ConfigParser
 6 import  pathlib
 7 import json
 8 
 9 ini_file = 'test.ini'
10 json_file = 'test.json'
11 
12 
13 cfg = ConfigParser()
14 cfg.read(ini_file)
15 
16 dest = {}
17 
18 for sect in cfg.sections():
19     # print(cfg.items(sect)) # [('a', '1000'), ('default-character-set', 'utf-8')]
20     dest[sect] = dict(cfg.items(sect))
21 
22 json.dump(dest, open(json, 'w'))
为什么要坚持,想一想当初!
原文地址:https://www.cnblogs.com/JerryZao/p/9600754.html