How to import from within a module

Le Snelson le_snelson at transtechinc.cc
Thu Dec 28 19:24:03 EST 2000


I am running Python 2.0 on Solaris 2.5x

I am attempting to import a module from in a function within a sort of
root module [init] - it contains only an initialization function.  The
intent is that configuration files will provide data to derive the name
of the module to be imported. All of the scripts provide the same
function names but for different underlying devices.

I am unable to get __import__( xxx ) to actually add xxx to any visible
dictionary. However, in the same file if I uncomment a line at the top
(global scope) that reads:
import xxx
Sure enough the xxx is in the list from dir(init).

I have tried all combinations of __import__(xxx, globals(), locals())
__import__(xxx, globals(), globals()) etc. I have also tried the "import
xxx" within the function I'm working on.  I expected syntax error but
got none as well as no discernible result.

Do I need to use the imp module to get this module found and loaded?

Any pointers to discussions or sample code appreciated.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: le_snelson.vcf
Type: text/x-vcard
Size: 340 bytes
Desc: Card for Le Snelson
URL: <http://mail.python.org/pipermail/python-list/attachments/20001228/4c9a385c/attachment.vcf>


More information about the Python-list mailing list