how to import a module dynamically

Randall Smith randall at
Fri Jan 2 21:56:43 CET 2004

How do I import a module when given the module name as input?

Between __import__, imp, and rexec, I'm very lost.  What I want to do 
seems so simple, but I don't know the best way to do it.  How would I 
import a module into the current namespace using the equivalent of these 
2 methods:

import modname


from modname import *

where modname is validated input


More information about the Python-list mailing list