Skip to content

Instantly share code, notes, and snippets.

@iomarmochtar
Last active December 31, 2019 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iomarmochtar/7446a41bda00bce3049b49e7949502a0 to your computer and use it in GitHub Desktop.
Save iomarmochtar/7446a41bda00bce3049b49e7949502a0 to your computer and use it in GitHub Desktop.
Simple way to convert .ini file to dict
from configparser import ConfigParser
from pprint import pprint
def as_dict(ini_file):
config = ConfigParser()
config.read_file(open(ini_file, 'r'))
return { x: dict(config[x]) for x in config.sections() }
pprint( as_dict('main.ini') )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment