import module and execute function at runtime

denny at sopris.net denny at sopris.net
Fri Jan 13 19:45:58 CET 2006


Hello, rookie here.

I'm trying to import a module at runtime using variables to specify
which module, and which functions to execute. for example:

mStr = "sys"
fStr = "exit"

# load mod
mod = __import__(mStr)
# call function
mod.fStr()

can i do this sort of thing? other suggestions?




More information about the Python-list mailing list