How to call a function of a module from a string with the function's name in Python?

PythonServer Side ProgrammingProgramming

The following code should call the required function

import fibo
result = getattr(fibo, 'baz')
print result

Similarly we can use getattr class instance bound methods, module-level methods, class methods and so on.

raja
Published on 07-Dec-2017 16:30:31
Advertisements