Cannot import a module from a variable

Christian Joergensen mail at
Sun Oct 15 17:36:50 CEST 2006

"Jia Lu" <Roka100 at> writes:

> 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 ? why?

Try using __import__(i) instead.

Christian Joergensen | Linux, programming or web consultancy  |     Visit us at:

More information about the Python-list mailing list