Parametrized module import

Jacek Generowicz jacek.generowicz at cern.ch
Thu Jul 8 06:58:51 EDT 2004


Oliver Fromme <olli at haluter.fromme.com> writes:

> You could create another module called "config" or "cfg"
> which contains some global variables.  You import it into
> your configurable module as well as into your main program.
> Then you can configure the module's behaviour via those
> global variables before importing the module.

Yes, my initial crappy prototype idea was to add configuration
information to the sys module, but this variation is much neater
... in fact, after the first 2 minutes of thinking about it, it looks
perfect :-)

However, one thing which keeps bothering me about the whole business,
is the possibilty of importing the module (with your chosen
configuration) after it has already been imported, without you knowing
it, with a different configuration. Ideally there should be some
warning about the fact that the configuration you specified is being
ignored as a result of the module already being imported ... and I
don't see how to achieve this.




More information about the Python-list mailing list