티스토리 뷰

공부

[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

'공부' 카테고리의 다른 글

[Spark] hive dynamic partition  (0) 2020.12.13
[Python] dict to string  (0) 2020.12.10
[Python] beautify JSON  (0) 2020.12.10
[Spark] string to date  (0) 2020.12.10
[Spark] `foreach` vs `foreachPartition`  (0) 2020.12.10
댓글