메서드에 대한 래퍼 함수를 작성할 수 있습니까?문자열 메서드를 함수로 처리 할 수 있습니까?
>>> lowtide = [ 'oh', 'i', 'do', 'like', 'to', 'be', 'beside', 'the', 'seaside' ]
>>> [ x.capitalize() for x in lowtide ]
['Oh', 'I', 'Do', 'Like', 'To', 'Be', 'Beside', 'The', 'Seaside']
>>> list(map(lambda x: x.capitalize(), lowtide))
['Oh', 'I', 'Do', 'Like', 'To', 'Be', 'Beside', 'The', 'Seaside']
>>> def mef(m):
... def _mef(m,x):
... return x.m()
... return partial(_mef, m)
...
>>> list(map(mef(capitalize), lowtide))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'capitalize' is not defined
당신의'mef' 함수는'xm'을'getattr (x, m)'로 바꾸면 작동 될 수 있습니다. –