[Tutor] setting program configuration for all files and modules ofa program
Tim Michelsen
timmichelsen at gmx-topmail.de
Tue Apr 15 21:16:19 CEST 2008
>>> Another option is to have the config settiongs in a normal
>>> Python module and just import it.
>
>> I think that the cfg-files are much more readable for others.
>
> More readable than:
>
> # Section Heading
> variable = value
>
> It looks pretty easy to read to me! :-)
>
> If its very complex you can use dictionaries:
>
> SectionFoo = {
> firstName : theValue
> second : anotherValue
> }
>
> Which is still pretty easy for the casual reader/maintainer
> and allows access like:
>
> import myconfig
> foo2 = myconfig.SectionFoo['second']
This seems like reinventing what the ConfigParser mdoule [1] already does.
I think I will read the config file once and the provide the parameters
with a settings.py module throughout the program and the modules.
Sounds like doing it twice.
But to my optinion Config Parser offers the following advantage:
- Readable
- All are strings => no strange 'mysetting' is needed.
Thanks for your help.
Kind regards,
Timmie
[1]http://docs.python.org/lib/module-ConfigParser.html
More information about the Tutor
mailing list