how to import a module dynamically

Randall Smith randall at tnr.cc
Fri Jan 2 16:30:11 EST 2004


Irmen de Jong wrote:
> 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.
> 
thanks




More information about the Python-list mailing list