Module Importing Question
Kent Johnson
kent37 at tds.net
Sat Oct 22 09:23:21 EDT 2005
James Stroud wrote:
> Hello All,
>
> I have two modules that I use interchangably depending on the circumstances.
> These modules are imported by yet another module. I want the "importation" of
> these two alternatives to be mutually exclusive and dependent on the state of
> the "outermost module"
>
> A diagram:
>
> mainApp ==imports==> aModule ==imports==> [oneMod | orTheOtherMod]
>
> I want the importing of oneMod or orTheOtherMod to depend on the state of the
> mainApp. aModule is frozen, as are oneMod and orTheOtherMod. How might I
> accomplish this?
I don't know what you mean by frozen, so maybe this is no good, but I would avoid having aModule look back at the state of mainApp. Instead use another module to communicate state. This could be a simple as
# in mainApp
import helper
if something:
import oneMod as theMod
else:
import orTheOtherMod as theMod
helper.theMod = theMod
import aModule
# in aModule
import helper.theMod as theMod
theMod.someFunction()
Kent
More information about the Python-list
mailing list