Cannot import a module from a variable

Bruno Desthuilliers onurb at xiludom.gro
Mon Oct 16 11:27:15 CEST 2006


Jia Lu wrote:
> Hi all:
> 
> I try to do things below:
>>>> import sys
>>>> for i in sys.modules.keys():
> 	import i
> Traceback (most recent call last):
>   File "<pyshell#67>", line 2, in <module>
>     import i
> ImportError: No module named i
> 
> But it seems that import donot know what is i ? 

The import statement expects a name (a symbol), not a string.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list