Most Pythonic way to store (small) configuration
Tim Chase
python.list at tim.thechases.com
Wed Aug 5 19:43:54 EDT 2015
On 2015-08-06 00:47, Marko Rauhamaa wrote:
> > There's a certain simplicity to simply having key/value pairs
> > separated by an "=" and then letting the application do whatever
> > it needs/wants with those key/value strings.
>
> That trap has lured in a lot of wildlife.
>
> What to do with lists?
>
> Is whitespace significant?
As I said, simple. Lists? Not in a simple config format. Though I
suppose, just like the .ini format, you could use a convention of
comma or space-separated list items. Or quoted white-space-separated
items like shlex handles nicely. Or if you really need, pass the
value portion of the key/value pair through ast.literal_eval()
Significant whitespace? Not usually simple (just stuck touching a
project where someone committed with tons of trailing whitespaces.
grumble), so strip 'em off as if they're an error condition. I've
never had a config-file where I wanted leading/trailing whitespace as
significant.
> Case in point, systemd configuration files:
The antithesis of "simplicity" ;-)
-tkc
More information about the Python-list
mailing list