Python:TypeError:super()参数1必须是类型,而不是classobj

时间:2018-09-07 18:55:23

标签: python python-2.7 typeerror

我正在尝试在SoloLearn.com上学习Python,其中一个模块是“简单”游戏。但是,让代码在我的机器上运行很麻烦。目前,我在外壳程序终端中使用Python 2.7。

#!/usr/bin/env python

class GameObject:
    class_name =""
    desc = ""
    objects = {}

    def __init__(self, name):
        self.name = name
        GameObject.objects[self.class_name] = self

    def get_desc(self):
        return self.class_name+ "\n" + self.desc


class Goblin(GameObject):
    def __init__(self, name):
        self.class_name = "goblin"
        self.health = 3
        self._desc = "A foul creature"
        super(Goblin,self).__init__(name)


    @property
    def desc(self):
        if self.health >= 3:
            return self._desc
        elif self.health == 2:
            health_line = "It has a wound on its knee."
        elif self.health == 1:
            health_line = "Its left arm has been cut off!"
        elif self.health <= 0:
            health_line = "It is dead."
        return self._desc + "\n" + health_line

    @desc.setter
    def desc(self, value):
        self._desc = value

这只是整个游戏的一部分。当我运行整个程序时,会出现以下错误:

Traceback (most recent call last):
  File "./game.py", line 40, in <module>
    goblin = Goblin("Gobbly")
  File "./game.py", line 21, in __init__
    super(Goblin,self).__init__(name)
TypeError: super() argument 1 must be type, not classobj

我尝试了许多不同的解决方案,但似乎都没有用。谁能告诉我哪里出问题了?

谢谢

0 个答案:

没有答案