how to import a module dynamically

Robert Brewer fumanchu at
Fri Jan 2 22:13:29 CET 2004

Randall Smith wrote:
> 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.

I was very lost, too, once upon a time. I wrote my eventual solution for
this into a Python Cookbook recipe:

...which is geared toward importing when you know the full package name,
for example "". Feel free to hack it up for your
own study and/or use.

Robert Brewer
Amor Ministries
fumanchu at

More information about the Python-list mailing list