티스토리 뷰

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

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

[Java] StringUtils.containsIgnoreCase  (0) 2020.10.16
[Java] HashSet foreach  (0) 2020.10.16
[Java] forEach with index  (0) 2020.10.03
[Spark] to_json (need to spark 2.1)  (0) 2020.10.03
[Java] class field name to JSON  (0) 2020.10.03
댓글