Application-global "switches"?

Marius Gedminas mgedmin at gmail.com
Thu Sep 17 16:53:19 CEST 2009


On Sep 4, 9:29 pm, kj <no.em... at please.post> wrote:
> The only solution I can come up with is to define a "dummy module",
> say _config.py, which contains only upper-case variables representing
> these global switches, and is imported by all the other modules in
> the application with the line "from _config import *".  During the
> early stages of the run, the script inspects the command-line flags,
> and if it finds a --continuing flag, it sets the variable
> _config.CONTINUATION_MODE to True.  (The last point implies that
> these variables are not strictly speaking read-only, since they
> most be set at the beginning of the run.  But after this initial
> setting, they should remain read-only.)

Be very very careful about "from _config import *".  If you import
a module that, in turn, imports _config this way, before you set
the initial values, that module will already have made its own copies
of all the variables and thus will not see the correct values.



More information about the Python-list mailing list