Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Module Importing Question

Reply
Thread Tools

Module Importing Question

 
 
James Stroud
Guest
Posts: n/a
 
      10-22-2005
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/
 
Reply With Quote
 
 
 
 
Kent Johnson
Guest
Posts: n/a
 
      10-22-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Module To Use Variables In A Second Module rshepard@nospam.appl-ecosys.com Python 4 09-28-2007 01:17 PM
doubt with importing module, given module name Pradnyesh Sawant Python 0 04-09-2007 05:22 PM
Re: module docstring, documentation,anything? please note is the module type/object NOT some module Maric Michaud Python 0 06-24-2006 12:42 PM
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM
Newbie question: importing module from C nick Python 0 11-28-2003 04:41 AM



Advertisments