I am currently using the ConfigParser module to read and parse the configuration for a python program. I understand that using ConfigParser streamlines the parsing and reading of configuration from file, however I am just curious as to what would be the tradeoffs if I simply use a json format for reading/writing config files. Wouldn't that be equally easy to parse etc, same as ConfigParser ?
With so many better options for configuration languages, there's no good reason to use JSON. If you are creating a new application, framework, or library that requires configuration choose something other than JSON.
The configparser module from Python's standard library defines functionality for reading and writing configuration files as used by Microsoft Windows OS. Such files usually have . INI extension. The INI file consists of sections, each led by a [section] header.
configparser comes from Python 3 and as such it works well with Unicode. The library is generally cleaned up in terms of internal data storage and reading/writing files.
JSON would be easy enough for your program to parse, but it would also burden the user with the responsibility of getting braces and quotes just right, and it would add unnecessary clutter to your configuration files. If that extra complexity is okay with you, or if you really need the kind of deep nesting that is slightly easier to parse in JSON than in flat config files, then by all means, use JSON. Some people even take this a step further and put their configuration in Python files.
Personally, I feel that configuration files that users might need to read or edit should be as simple as possible, so I use (a subset of) the configparser syntax. If I need hierarchy, I simply represent it with dots:
parent.child1 = foo
parent.child2 = bar
When I want to avoid requiring [sections]
in my config files, I can either trick configparser into not needing them, or use a TOML parser instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With