相关疑难解决方法(0)

TypeError:Super不接受关键字参数?

首先,这是我的代码:

class Enemy():
    def __init__(self, name, hp, damage):
        self.name = name
        self.hp = hp
        self.damage = damage


    def is_alive(self):
        """Checks if alive"""
        return self.hp > 0

class WildBoar(Enemy):
    def __init__(self):
        super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__()

class Marauder(Enemy):
    def __init__(self):
        super(Marauder, name="Marauder", hp=20, damage=5).__init__()


class Kidnappers(Enemy):
    def __init__(self):
        super(Kidnappers, name="The Kidnappers", hp=30, damage=7).__init__()
Run Code Online (Sandbox Code Playgroud)

当我编译这个时,我收到此错误:

super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__()
TypeError: super does not take keyword arguments
Run Code Online (Sandbox Code Playgroud)

我试着寻找任何帮助,但我找不到任何东西.我也有一些Kwargs在其他类的超级,但这些是提出任何类型的问题(截至目前).那可能是什么导致了这个?我也看到有人说super在基类中放置一个将修复它,但它不起作用(我传入了Base类中的相同参数__init__).

python inheritance class super

15
推荐指数
1
解决办法
7576
查看次数

标签 统计

class ×1

inheritance ×1

python ×1

super ×1