返回两个函数的函数

时间:2017-10-14 01:43:13

标签: python function

功能菜单5向用户返回一条消息。我想同时用户调用此函数,它调用另一个类似的函数,它将消息发送给另一个人。 这是代码:

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)

1 个答案:

答案 0 :(得分:0)

如果你想要某个函数的返回值,你需要明确地存储它:

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 - 它只是没有对返回值执行任何操作。