Why shouldn't you put config options in py files

HT ht at example.com
Thu Dec 4 21:09:57 CET 2008


Chris Rebert wrote:
> On Thu, Dec 4, 2008 at 11:35 AM, HT <ht at example.com> wrote:
>> FOO = {'bar': ('a': 'b'), 'abc': ('z': 'x')}
> 
> I'll assume you meant ('a', 'b') as colons in parens don't make sense.

Yes, sorry.

> Well, it is pretty weird to be allowed to put arbitrary code in a mere
> config file.

The end result is that we want to have that dictionary in that variable
(most of the config values would just be simple values or lists and this
dict is among the most complex), but it doesn't mean that the config
file would need to have arbitrary code. I can think of many ways to
achieve that (haven't actually tried writing the code to read these yet):

[my_foos]

bar = a, b
abc = z, x

or maybe

foo.bar= a, b
foo.abc= z, x

or something like that. You'd read the values with ConfigParser, then
process them to get the dictionary.

> Have you considered using JSON for the config file format instead? It
> shares Python's syntax for literals, so you could do:

No, hadn't thought of that. Might be doable, need to think about that
some more. Thanks.



More information about the Python-list mailing list