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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-08-13
  • 2021-09-16
  • 2022-01-10
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2022-01-26
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-12-06
相关资源
相似解决方案