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