I really like Python's ConfigParser
API. I find using an INI style config file to be very readable and nice to work with as opposed to using XML or JSON. There are very few cross-platform libraries available to do this. However, when you have Cython, all you need is Python.
For this example, we will create a sample INI
configuration file and write a simple API to access a list of sections, list of keys available in a section, and a way to get the value from a specified key within a section. These three functions will allow a programmer to access any INI
file.
A sample INI file could be:
[example] number = 15 path = some/path/to/something [another_section] test = something
An INI file is comprised of sections within the square brackets, followed by keys and values. It's a very simple way of doing configuration. Python's API allows for variables and substitution depending on the flavor of the ConfigParser
. Firstly, we need a way to query the list of sections...