__import__ woes
Erik Max Francis
max at alcyone.com
Thu Mar 27 21:57:18 EST 2003
Rich Davis wrote:
> When I try to "__import__" from the command-line like
>
> >>> __import__("test")
> <module 'test' from 'test.pyc'>
> >>> test.doIt("test string")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> NameError: name 'test' is not defined
Yes, this is expected behavior. __import__ does not behave the same way
that the import statement does. __import__ _returns_ the imported
module without inserting it anywhere in the namespace.
You want
testModule = __import__('test')
testModule.doIt(...)
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ It's soulful music. It doesn't necessarily sound like ... soul ...
\__/ Sade Adu
Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
A personal guide to Quake III Arena.
More information about the Python-list
mailing list