"chicken and egg" problem with modules and global vars

Graham Guttocks graham_guttocks at yahoo.co.nz
Sun Apr 29 15:27:30 EDT 2001


Greetings,

I'm running into a sort of "chicken and egg" problem involving
modules, global variables and getopt command-line arguments and would
appreciate some direction.

I'm importing a module named "Defaults" at the top of my program which
defines a number of default values as well as parses a user
configuration file for more default values.  These values are used in
the program's function definitions including main().

I need the ability for the user to override the default location of
his custom config-file which is defined in "Defaults".  I'm doing this
with getopt in main() by appending to __builtin__ so that "Defaults"
can access it.

The problem is that since "Defaults" is imported at the top of the
program, the default config-file location is set as soon as this
module is imported.  I need getopt to be read first, but I can't just
move "import Defaults" down into the body of main() because the
function definitions above main() rely on it.

Any ideas?

Regards,
Graham

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/




More information about the Python-list mailing list