DTD Parsing
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Wed Nov 10 22:07:45 EST 2010
In message <mailman.803.1289374804.2218.python-list at python.org>, Ian Kelly
wrote:
> On 11/9/2010 11:14 PM, r0g wrote:
>>
>> 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
Not a good idea. Because if there any mistakes in the config, you would like
to print useful explanatory error messages to help the writer of the config
file figure out what they’ve done wrong, rather than relying on them to
understand Python exception tracebacks. Also your config validation rules
may not map easily to Python language rules.
More information about the Python-list
mailing list