Pythonの文法について質問です。
Pythonで()が2連続するのはどういう用法、意味があるのでしょうか。
Amazon alexaのskill開発にあたり、デフォルトのpythonコードに下記のようなコードがあり疑問に思ったため質問いたしました。
return ask_utils.is_request_type("LaunchRequest")(handler_input)
初歩的な質問ですが、ご回答いただけると幸いです。
スタック・オーバーフローはプログラマーとプログラミングに熱心な人のためのQ&Aサイトです。すぐ登録できます。
登録してこのコミュニティに参加するask_utils.is_request_type
は関数を返す高階関数ではありませんか?
https://python.atelierkobato.com/high/#outline__1_2
return ask_utils.is_request_type("LaunchRequest")(handler_input)
は以下を一行で書いたものです。
func = ask_utils.is_request_type("LaunchRequest")
return func(handler_input)
def is_request_type(request_type):
# type: (str) -> Callable[[HandlerInput], bool]
"""A predicate function returning a boolean, when request type is
the passed-in type.
The function can be applied on a
:py:class:`ask_sdk_core.handler_input.HandlerInput`, to check
if the input request type is the passed in request type.
:param request_type: request type to be matched with the input's request
:type request_type: str
:return: Predicate function that can be used to check the type of
the request
:rtype: Callable[[HandlerInput], bool]
"""
def can_handle_wrapper(handler_input):
# type: (HandlerInput) -> bool
return (handler_input.request_envelope.request.object_type ==
request_type)
return can_handle_wrapper
can_handle_wrapper
が関数になっています。