What’s the most pythonic method for specifying a configuration file?

I’m writing a daemon script in Python and would like to be able to specify settings in a file that the program expects to read (like .conf files). The standard library has configparser and xdrlib file formats, but neither seems pythonic; the former being a Microsoft standard and the latter a Sun Microsystems standard.

I could write my own, but I’d rather stick to a well-known and documented standard, than reinvent the wheel.

Best answer

IMHO : Do NEVER touch the ConfigParser Module, its outdated (reads: obviously not brought up to date) and has quite some quirks. API for comments? Forget it! Access to the DEFAULT-Section? LOL! Wondering about not parsed Config-Fields? Well guess what: ConfigParser iterates over all your config files and fails silently (glossing over) to maybe EVENTUALLY do a condensed Exception-Trace over ALL Errors. It’s not easy to find out which error belongs to which file. No nested config-sections…

Rather CSV then ConfigParser!

IMO: Use Json for config-files. Very flexible, direct mapping between python-data structures and Json-String representation is possible and still human readable. Btw. interchange between different languages is quite easy.

Curly-Braces in the file aren’t that pretty, but you can’t have it all! 馃槈