Module Importing Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Stroud

    #1

    Module Importing Question

    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 "importatio n" 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


  • Kent Johnson

    #2
    Re: Module Importing Question

    James Stroud wrote:[color=blue]
    > 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 "importatio n" 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?[/color]

    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.someFunc tion()

    Kent

    Comment

    Working...