Hello,

> I maintain a few configuration files in Python syntax (mainly nested

> dicts of ints and strings) and use execfile() to read them back to

> Python. This has been working great; it combines the convenience of

> pickle with the readability of Python. So far each configuration is

> contained in a single standalone file; different configurations are

> completely separate files.


> Now I'd like to factor out the commonalities of the different

> configurations in a master config and specify only the necessary

> modifications and additions in each concrete config file. I tried the

> simplest thing that could possibly work:

I've been working with a similar problem; indeed, posted a question about it 
several weeks ago.

I
can't speak to the issue of factoring out commonalities, but I've been
trying to find a really simple, elegant way to avoid the exec
functions. My approaches have been variations in __import__() and
loading as file, etc. Everything I've tried seems a bit kludgy. One
issue, as I recall, was that __import__() became rather unreliable when
you crossed directory boundaries.

Question: Why do so many sources discourage the use of exec(), execfile(), etc.?

Comment:
The Karrigell Python web framework
(http://karrigell.sourceforge.net/en/include.htm) has a truly elegant
function for loading stuff like some_config.py called Include(). I
haven't looked at the source, but it is very handy. I really wish it
was basic Python function.

All the best,

Lloyd



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

Reply via email to