Tag: config configparser optparse


Parsing Configuration Files Bad for your Health

June 3rd, 2010 — 1:15pm

As part of my angst-driven search for stuff that other people might have done, and published, that would save me maintaining my own code, I took a look at things to handle INI files. Oh dear. They are everywhere, and they all do different things.

Python does provide a mechanism for reading INI files. ConfigParser is the basic in-built module, and it handles a reasonably simple form of config file, with some variable substitution. It is a starting point, but there are issues:

  • Command line programs would like to be able to override entries in the config file with optional command line settings.
  • The main problem here is that optparse has a different API and does not naturally recognise the kind of block structure that INI files allow.

  • Setting the configuration file name from the command line does not play well with the idea of overriding settings from an, as yet, unread config file.
  • When building an application made up of multiple packages, each with its own configuration, the config file should be able to integrate the configs for these packages, while keeping them appropriately separate.
  • It would be nice to be able to use different text formats. Conversely, there is no reason why the API should constrain the file format.

There are probably other issues, but these keep coming up. I am relieved, slightly, to find that many people have thought about this, and there has even been discussion in the Python wiki (ConfigParserShootout). I am also depressed. The discussion came to no great conclusion, and the issues are still open.

So I keep the old code, then.

Comments Off on Parsing Configuration Files Bad for your Health | Development

Back to top