On 10/11/10 20:38, Ian wrote:
On Nov 10, 1:05 am, r0g<aioe....@technicalbloke.com>  wrote:
That's five whole lines of code. Why go to all that trouble when you can
just do this:

import config

Heh, mainly because I figure the config module will have a lot more
options than I have use for right now and therefore the docs will take
me longer to read than I will save by not just typing in the above ;)

I think you misunderstand me.  There is no config module and there are
no docs to read.  It's just the configuration file itself written as a
Python script, containing arbitrary settings like:


So you're not talking about this then?...

http://www.red-dove.com/config-doc/

I see. You're suggesting writing config files IN the language you're already writing in?

Indeed that's what I do in many situations, it has the advantage of working in any scripting language (I do the same in PHP fairly often, as do several big projects like Drupal) and of course it spares you a bit of code.

However, if your config file it's meant to be distributed / editable by end users you don't necessarily want them to need a full understanding of python syntax to do it.

Also, actually parsing config files (rather than just importing namespaces) gives you an opportunity to deal with any syntax errors on a case by case basis i.e. skip, fail, issue warning etc. Just importing code gives you a kind of 100% consistency or death situation and while that might be exactly what you want many times there may be situations where you want a bit more fine grained control!

Roger


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

Reply via email to