[Tutor] How to import one function from another program (not as header)

alan.gauld@bt.com alan.gauld@bt.com
Thu, 23 Aug 2001 17:05:06 +0100

First if you know modulename and funcname you should be 
able to just call them, but assuming you may be reading
them dynamically...

> def something(modulename, funcName):
>     module = __import__(modulename)
>     func = module.funcName    

      eval('func = '+modulename+'.'+funcname)
      return func

foo = something('sys','exit')
foo()  # should exit!

I think.

Alan G