Passing options between modules

Peter Hansen peter at engcorp.com
Fri May 21 13:21:31 EDT 2004


Chris wrote:

> I'm trying to come up with a not-so-ugly manner of passing many
> command-line options between modules.

In a pinch (i.e. if the rest of your application is such that
you don't have a cleaner alternative), create an empty module
called something like Globals.py and set values in its namespace
to reflect the command line options.  Then any module that
needs it can just "import Globals" to get access to the data.

All the usual "don't do that" cautions about globals apply,
including how they can make a mess of your code, make it
very hard to tell how data gets passed around, reduce
maintainability, etc.

Without knowing more about the structure and purpose of
the code, it's hard to suggest something that is clearer
more suitable and would definitely work.

-Peter



More information about the Python-list mailing list