공부
[Python] call method by name of function
승가비
2020. 12. 10. 11:43
728x90
import foo
method_to_call = getattr(foo, 'bar')
result = method_to_call()
result = getattr(foo, 'bar')()
https://stackoverflow.com/questions/3061/calling-a-function-of-a-module-by-using-its-name-a-string
Calling a function of a module by using its name (a string)
What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module foo, and I have a string whose content ...
stackoverflow.com
728x90