DTD Parsing

Ian Kelly ian.g.kelly at gmail.com
Wed Nov 10 02:36:37 EST 2010


On 11/9/2010 11:14 PM, r0g wrote:
> Me too when possible, TBH if I only needed strings and there was no
> pressing security issue I'd just do this...
>
> config = {}
> for line in (open("config.txt", 'r')):
> if len(line) > 0 and line[0] <> "#":
> param, value = line.rstrip().split("=",1)
> config[param] = value

That's five whole lines of code.  Why go to all that trouble when you 
can just do this:

import config

I kid, but only partially.  Where this really shines is when you're 
prototyping something and you need to configure complex object 
hierarchies.  No need to spend time writing parsers to generate the 
hierarchies; you just construct the objects directly in the config. 
When the project becomes mature enough that configuration security is a 
concern, then you can replace the config with XML or whatever, and in 
the meantime you can focus on more important things, like the actual 
project.

Cheers,
Ian




More information about the Python-list mailing list