In message <[email protected]>, 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.
--
http://mail.python.org/mailman/listinfo/python-list