2

I have INI file, it contains next:

{
   "input": {
      "json": "good.json",
      "csv": "good.csv",
      "encoding": "utf-8"
   },
   "output": {
      "fname": "res.txt",
      "encoding": "utf-8"
   }
}

so basically inside ini file I have json. I can no find a way to work with keys inside the file without using configparser . Please help

alesia
  • 23
  • 2
  • Use the `configparser` module: https://stackoverflow.com/questions/8884188/how-to-read-and-write-ini-file-with-python3. – Daniel Jul 18 '21 at 23:19

1 Answers1

0

Have you tried just opening it as a json file? Since the ini file is a text file, it should * just work *

import json

# I saved your example in a text file called test.ini and 
# put it in the same folder as this script
with open('test.ini', 'r') as f:
    data = json.load(f)

The contents of your ini file will be in data, which will be a dictionary.

Jgd10
  • 497
  • 2
  • 14
  • `json` is a built-in package so it should be available to you – Jgd10 May 13 '21 at 09:33
  • 1
    I truly did few times but it always returned an error. well, maybe I had to bother people first. now it is perfectly working, thanks ! – alesia May 13 '21 at 10:37
  • You're welcome! I'm not sure if my answer worked based on your comment? But if it did I'd appreciate it if you could accept it! – Jgd10 May 13 '21 at 10:55