I am writing a class to parse various config files. It contains methods for yaml
files and ini
+ cfg
files.
Parsing yamls works fine, but I have a problem with those two other ones. Basically I read them, I parse them, but if e.g. my config.cfg
file looks like this:
[foo]
bar: True
The value for config['foo']['bar']
will be 'True'
, not True
, so I end up with a string.
I don't want to force the users of my class to convert the given value. Is there a way to get around this, so the strings become booleans?
P.S After reading a configuration I convert return a dictionary of read values, like this:
config_parser = configparser.ConfigParser()
config_parser.read(config_file_path)
return {section: dict(config_parser.items(section)) for section in config_parser.sections()}