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'))

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM