Options, ConfigParser, modules, and SQLObject connections

Istvan Albert ialbert at mailblocks.com
Tue Oct 12 15:17:06 EDT 2004


Robin Munn wrote:

> I'm sure others have faced similar problems before. How have you
> managed?

What I do in a similar situation is to set an environment
variable. This environment variable points to
the .ini configuration file.

Then I put the configuration loading in the body of
the module. That way when it gets imported for the
first time it executes the instructions.

--- globalconf.py ---
# put whatever code you need here to
# fetch the environment variable and process the file
db_filename = 'database_name'

--- sqldefs.py ---
import globalconf
import sqlobject
__connection__ = sqlobject.SQLiteConnection(globalconf.db_filename)

Istvan.



More information about the Python-list mailing list