Why shouldn't you put config options in py files

2008-12-04 Thread HT
A colleague of mine is arguing that since it is easy to write config like:

FOO = {'bar': ('a': 'b'), 'abc': ('z': 'x')}

in config.py and just import it to get FOO, but difficult to achieve the
same using an ini file and ConfigParser, and since Python files are just
text, we should just write the config options in the Python file and
import it.

I can think of lots of arguments why this is a bad idea, but I don't
seem to be able to think of a really convincing one.

Anyone?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why shouldn't you put config options in py files

2008-12-04 Thread HT
Chris Rebert wrote:
> On Thu, Dec 4, 2008 at 11:35 AM, HT <[EMAIL PROTECTED]> 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.
--
http://mail.python.org/mailman/listinfo/python-list