Most Pythonic way to store (small) configuration
rustompmody at gmail.com
Wed Aug 5 06:55:04 CEST 2015
On Wednesday, August 5, 2015 at 10:19:11 AM UTC+5:30, Michael Torrie wrote:
> On 08/04/2015 08:44 PM, wrote:
> > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote:
> >> In many of my projects I put basic config variables in a file like
> >> config.py and import that in each module that needs it. The config
> >> module doubles as a global namespace for sharing between modules as well.
> > What about JSONP? That is, a file consisting exactly of "config_data =
> > [JSON object]" That would get you some of the benefits of having your
> > config file exist as a python module, but still allow it to be examined
> > by other tools, written out, etc.
> But I don't need it to be examined by other tools. So the added
> complication of yet another layer isn't worth it or needed. Python's
> syntax is simple enough that a person with a text editor can certainly
> do it. Again, context is everything. My programs are written for
> mostly my own use. If I was writing a system that was like, say,
> Apache, I would certainly do a DSL with a robust error checking and
> reporting system that could clearly help people with syntax errors, etc.
I think the main point is Cameron's
> So on the whole I am against python code as the config file format. Really,
> who needs a Turing complete configuration file?
stated more strongly: I sure dont want to use something Turing complete
from something that is inherently more trivial.
And if the cost is of matching the trivial format to the trivial-izing reader
(say json) it seems like a small price to pay.
In the past Ive always recommended yaml even though the cost is higher --
a separate install [yeah Ive had clients tell me that yaml's out because of that]
[Does yaml have comments?]
More information about the Python-list