Module Importing Question

J

James Stroud

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 realize that this is a workaround for poorly thought out
dependencies, but in my defense, have you seen just about anything else in
this world (California Freeways, Tax Forms, A Flow-Chart of Human Metabolic
Pathways, umm...whatever)?

James



--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
K

Kent Johnson

James said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top