random.random - random()不带参数(给定1个)

时间:2015-02-04 16:18:44

标签: python random

我试图让random.random从cmd_advice中的函数列表中选择(我假设它是如何工作的?)但是我的调试器向我显示TypeError:random()不带参数( 1给出)。

我是新人,所以如果这看起来很愚蠢我会道歉。

    # minqlbot - A Quake Live server administrator bot.
# Copyright (C) Mino <mino@minomino.org>

# This file is part of minqlbot.

# minqlbot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# minqlbot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with minqlbot. If not, see <http://www.gnu.org/licenses/>.

import minqlbot
import random

class fun(minqlbot.Plugin):
    def __init__(self):
        self.add_command("cookies", self.cmd_cookies)
        self.add_command("<3", self.cmd_heart, channels=("chat", "team_chat", "tell"))
        self.add_command("wife", self.cmd_wife)
        self.add_command("advice", self.cmd_advice)

    def cmd_cookies(self, player, msg, channel):
        channel.reply("^7For me? Thank you, {}!".format(player))

    def cmd_heart(self, player, msg, channel):
        s = ("^1\r oo   oo"
             "\no  o o  o"
             "\no   o   o"
             "\n o     o"
             "\n  o   o"
             "\n   o o"
             "\n    o")
        channel.reply(s.replace("o", "\x08"))

    def cmd_wife(self, player, msg, channel):
        channel.reply("^4I love my wife more than anything in the whole wide world!")

    def cmd_advice(self, player, msg, channel):
        def advice1():
            channel.reply("This is advice1")
        def advice2():
            channel.reply("This is advice2")
        def advice3():
            channel.reply("This is advice3")
        choice = [advice2(), advice3(), advice1()]
        random.random(choice)

1 个答案:

答案 0 :(得分:5)

使用random.choicedocs)代替random.random