[Tutor] setting program configuration for all files and modules ofa program
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
> the functional code that provides the calculation operations. This
> 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
> ConfigParser object in each module?
> I through of having a special module "settings.py" which I could use
> read in the configuration from the file and then import this in each
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...
Why all the parens around the error strings in your code?
Author of the Learn to Program web site
More information about the Tutor