[Tutor] How to import one function from another program (not as header)
Remco Gerlich
scarblac@pino.selwerd.nl
Thu, 23 Aug 2001 10:34:26 +0200
On 0, Hanna Joo <hanna@chagford.com> wrote:
> I have two programs. I would like to import a function from another program
> but want to pass name of the function as a variable. Is this possible?
>
> prog a:
>
> def something(modulename, funcName):
> module = __import__(modulename)
> func = module.funcName ( == doesn't work.. complains that module has
> no attribute 'funcName')
>
> I would like to keep funcName as a variable.. How can I do this?
> Any help will be appreciated.
func = getattr(module, funcName)
--
Remco Gerlich