There are 2 files one.cfg , two.cfg .

How to encode these 2 files into one files.json ?

  • 2
    Explain with an example what is and what you want to get at the output. - 0xdb
  • Vote for the answer please :) - alex-rudenkiy

1 answer 1

First, we load the contents of our 2 files, and then we load them into the json structure, then we open a new file where we will save it and save it with the dump command, everything is simple :)

 import json a = open('one.cfg', 'r') b = open('two.cfg', 'r') data = { 'one.cfg' : a.read(), 'two.cfg' : b.read(), } with open('data.json', 'w') as f: json.dump(data, f)