티스토리 뷰

Python/Note

Python methodcaller(메소드콜러)

j0n9m1n1 j0n9m1n1 2019.11.08 10:38
from operator import methodcaller

s = 'python method caller example'

upcase = methodcaller('upper')
print(upcase(s))

hiphenate = methodcaller('replace', ' ', '-')
res = hiphenate(s)
print(res)

함수처럼 쓸 수 있음