如何从函数函数中的返回值中获取变量?

时间:2015-06-20 00:58:55

标签: python

我想将发送邮件!player1!player2的返回播放器放入一个简短的列表中,以便我以后可以使用它们,但我似乎无法了解如何从函数内的函数中获取返回的变量。我看到了Closure的一些内容,我认为这是一个例子,但是即使按照这个例子,我似乎无法得到返回的值,所以我可以分配它们。

    def players(sender, event):

    def getplayer():

        msg = event.parsed[0]['msg']

        if msg == '!player1':
            BotBasicFunction.sendmsg(msgg='{} has joined the game!'.format(hasplayer()))
            hasplayer()

        if msg == '!player2':
            BotBasicFunction.sendmsg(msgg='{} has joined the game!'.format(hasplayer()))
            hasplayer()

    def hasplayer():
        invoker = event.parsed[0]['invokername']
        return invoker

    parsedmsg = event.parsed[0]['msg']

    players = [getplayer(), getplayer(), getplayer(), getplayer()]

    if parsedmsg == '!players':
        BotBasicFunction.sendmsg(msgg='{}'.format(players))

0 个答案:

没有答案