![](/img/trans.png)
[英]Python function that takes two functions and returns the concatenated function?
[英]Function that returns two functions
功能 menu5 向用戶返回一條消息。 我同時希望用戶調用這個函數,它調用另一個類似的函數,將消息發送給另一個人。 這是代碼:
def menu5(self, message=None, match=None, to=None):
# Retransfer the requester's phone
number = message.getFrom()
# Cut after the @
number = number.split('@')
# Separate only the number
number = number[0]
# Delete the 55
number = number[2:13]
# Person who will receive the message
toSend = '5527999999999@s.whatsapp.net'
# Function call to be triggered
self.operator(msg=number, op=toSend)
return textMessageProtocolEntity(txtMenu5, to=message.getFrom())
def operator(self, to=None, msg=None, op=None):
return TextMessageProtocolEntity(msg, to=op)
如果你想要某個函數的返回值,你需要顯式存儲它:
def menu5(self, message=None, match=None, to=None):
# ...
# Function call to be triggered
txtmsg = self.operator(msg=number, op=toSend)
return TextMessageProtocolEntity(txtMenu5, to=message.getFrom()), txtmsg
函數menu5
現在返回一個包含兩個TextMessageProtocolEntity
的二元素元組。 請注意,您的原始代碼總是按預期調用self.operator
- 它只是沒有對返回值執行任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.