Last active
December 31, 2019 07:09
-
-
Save iomarmochtar/7446a41bda00bce3049b49e7949502a0 to your computer and use it in GitHub Desktop.
Simple way to convert .ini file to dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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