Module Importing Question

Discussion in 'Python' started by James Stroud, Oct 22, 2005.

  1. James Stroud

    James Stroud Guest

    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/
    James Stroud, Oct 22, 2005
    #1
    1. Advertising

  2. James Stroud

    Kent Johnson Guest

    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
    Kent Johnson, Oct 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Crow

    Error importing cgi module

    Sam Crow, Jun 27, 2003, in forum: Python
    Replies:
    2
    Views:
    765
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Jun 27, 2003
  2. nick
    Replies:
    0
    Views:
    289
  3. plb
    Replies:
    2
    Views:
    340
  4. Pradnyesh Sawant

    doubt with importing module, given module name

    Pradnyesh Sawant, Apr 9, 2007, in forum: Python
    Replies:
    0
    Views:
    273
    Pradnyesh Sawant
    Apr 9, 2007
  5. -ecosys.com
    Replies:
    4
    Views:
    293
    Calvin Spealman
    Sep 28, 2007
Loading...

Share This Page