How to make a conditional import???

Peter Arwanitis arwanitis at iabg.de
Fri Nov 10 09:09:55 EST 2000


hi there,

I'm ever trapped by 'import'-problems :)

Actually:

#Start of codeblock############
from string import *

def selectProjectType():
    #...    skipped
    if projectType == 'phys':
        from pyhsModule import *
    else:
        from logicModule import *

def processProject(value):
    v = translate(value)    #this function is different in phys and
                            #logicModule, but have the same name
    return v

#End of CodeBlock#############

everybody know the effect... the import statement in selectProjectType() is
only processed locally!

But I need it global, like the string import...

PLEASE: I need a quick solution, and not a code-philosophy-thread :-)
I know, that I can make it better on other ways (and without from...)

BUT is there a obfuscated solution to make this import happen in global
scope???

thanks
Peter
(=PA=) aka spex66







More information about the Python-list mailing list