[Tutor] setting program configuration for all files and modules ofa program

Alan Gauld alan.gauld at btinternet.com
Tue Apr 15 01:19:10 CEST 2008


"Tim Michelsen" <timmichelsen at gmx-topmail.de> wrote

> But I would like to modularize my code and separate the GUI code 
> from
> the functional code that provides the calculation operations. This 
> will
> help to expand the functionality at a later stage. I want to achieve
> this through splitting the code into different modules.

A good plan

> How can I provide the settings stored in the configuration file
> throughout my program to all functions without needing to initiate 
> the
> ConfigParser object in each module?
>
> I through of having a special module "settings.py" which I could use 
> to
> read in the configuration from the file and then import this in each 
> module.

Yes, thats the way I'd recommend.

> Is there a more decent and elegant way?

Why do you feel that is "indecent" or inelegant?

Another option is to have the config settiongs in a normal
Python module and just import it. That is less appealing if
the config file is shared with a non python program, but if
its all Python then that's a much simpler approach...

PS.
Why all the parens around the error strings in your code?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list