Most Pythonic way to store (small) configuration

Ben Finney ben+python at benfinney.id.au
Sun Aug 2 13:54:59 CEST 2015


Cecil Westerhof <Cecil at decebal.nl> writes:

> Because of this I think a human readable file would be best.

I agree with that criterion; in the absence of compelling reasons
otherwise, human-readable and -editable text is a good default.

> Personally I do not find XML very readable. So a conf or json file
> looks the most promising to me. And I would have a slight preference
> for a json file.

XML and JSON should both be considered data serialisation formats only.

JSON is human-readable to an extent, but it is quite brittle, and there
are no comments permitted in the syntax.

So, both XML and JSON should be considered write-only, and produced only
for consumption by a computer; they are a poor choice for presenting to
a human.

The “INI” format as handled by the Python ‘configparser’ module is what
I would recommend for a simple flat configuration file. It is more
intuitive to edit, and has a conventional commenting format.

If it were more complex I might recommend YAML, which is a very
widespread, flexible hierarchical format, that still allows fairly
natural editing and commenting. Its main downside (as opposed to INI
format) is that the Python standard library does not support it.

-- 
 \         “Simplicity and elegance are unpopular because they require |
  `\           hard work and discipline to achieve and education to be |
_o__)                                appreciated.” —Edsger W. Dijkstra |
Ben Finney



More information about the Python-list mailing list