Most Pythonic way to store (small) configuration

Michael Torrie torriem at gmail.com
Wed Aug 5 06:55:59 CEST 2015


On 08/04/2015 08:19 PM, Cameron Simpson wrote:
> So on the whole I am against python code as the config file format. Really, who 
> needs a Turing complete configuration file?

In Django's case, since you're intimately referring to certain classes
and methods, particularly in the url mapping section, I think using
straight Python is the way to go.  It's the most flexibility for the
least amount of work. And someone working with Django already has
familiarity with both Django and Python.  I'm sure everything could be
put in a DSL, but then you'd be inventing a subset of Python anyway.

And like I say, since the same person editing the config file is also
editing the other Django project files, the issue of code injection is
moot; he's already doing that!

So for the OP's case, if his needs are simple like mine are, then a
simple python file he imports could be just fine.  I'm hard pressed to
make a case for something different if the needs are simple like that.

> Go with something simple, both in syntax and semantics. It is easier to read, 
> easier to write/modify, and easier to access from multiple tools.

Python as configuration is simpler for my purposes, in both ways.  And
multiple tools for me == text editors.  I have no need of
machine-generated config files.  Maybe Cecil doesn't either.  Such tools
are of limited use anyway in my experience.  For example webadmin never
cut it for me.  Neither did the old web-based Samba configurater.


More information about the Python-list mailing list