How do I call a function, using a string with the function's name? For example:
import foo
func_name = "bar"
call(foo, func_name) # calls foo.bar()
objectpythonreflection
How do I call a function, using a string with the function's name? For example:
import foo
func_name = "bar"
call(foo, func_name) # calls foo.bar()
Best Answer
Given a module
foo
with methodbar
:getattr
can similarly be used on class instance bound methods, module-level methods, class methods... the list goes on.