import module and execute function at runtime

iapain iapain at gmail.com
Fri Jan 13 14:30:09 EST 2006


Hi,
if you want to import module dynamically, you can use __import__ ..
always remember modules are objects  ..

mStr="sys"
mod=__import__(mStr)
# Now u can use mod.version .. but cant specify the attribute using
other variable, like u did
mod.version

should read it
http://diveintopython.org/functional_programming/dynamic_import.html




More information about the Python-list mailing list