【问题标题】:Parameter Error in Python - Text Adventure GamePython中的参数错误 - 文字冒险游戏
【发布时间】:2013-04-24 22:34:24
【问题描述】:

尝试使用 Python 中的游戏引擎进行文本冒险。无论如何,我不断收到此错误消息。 TypeError: module.__init__() takes at most 2 arguments (3 given)

这是我的代码:

from engine import game
from engine import event
from engine import place


class TextAdventureGame(game):
    def __init__(self):
        super(TextAdventureGame, self).__init__()
        self.introduction = ('''Welcome to Can You Escape text adventure game.
You wake up in a dark room and you have no idea where you are.''')

为什么会出现这个错误?

class TextAdventureGame(game): TypeError: module.__init__() takes at most 2 arguments (3 given)

【问题讨论】:

  • 你是如何实例化你的类的?
  • 考虑将问题的标题更改为反映您具体问题的内容。
  • 1:这是你的全部代码吗? 2:如果你删除super(TextAdventureGame, self).__init__(),你会得到同样的错误吗?

标签: python class import init


【解决方案1】:

这个问题以一种很难回答的方式提出,但从它的外观来看,我会说错误就在这里:

class TextAdventureGame(game):

它说的是module.__init__(),而不是TextAdventureGame.__init__(),这让我觉得game 是一个以奇怪的方式使用的模块。但是,如果不了解您的代码、game 是什么或查看堆栈跟踪,我们真的无能为力。

【讨论】:

    【解决方案2】:

    game 是一个模块。您应该改用一个类作为基类。

    >>> import os
    >>> class C(os):
    ...   pass
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: module.__init__() takes at most 2 arguments (3 given)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多