Re: import module and execute function at runtime

2006-01-13 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote: > 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() getattr(mod, fStr)() -- Giovanni Ba

Re: import module and execute function at runtime

2006-01-13 Thread iapain
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/funct

import module and execute function at runtime

2006-01-13 Thread denny
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? -- http://