how to import a module dynamically

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Fri Jan 2 16:01:04 EST 2004


Randall Smith wrote:
> How do I import a module when given the module name as input?


> import modname

exec "import "+your_module_name


> from modname import *

exec "from %s import %s" % (your_module_name, your_imported_symbol)

HTH,
Irmen.




More information about the Python-list mailing list