<p>因为你在没有<code>difficulty</code>的情况下调用了<code>super(Goblin, self).__init__(self, power, MaxHP, magic, MaxMP, speed, name)</code>。如果在2.x上(考虑到使用<code>super</code>的旧方法,我猜您一定是这样),您可能还希望像<code>class Enemy(object)</code>那样继承,以确保<code>Enemy</code>是一个新样式的类。</p>
<p>下面是一个简单的例子:</p>
<pre><code>class Animal(object):
def __init__(self, talk):
print '__init__ Animal: ', talk
class Cat(Animal):
def __init__(self, talk='meow'):
print '__init__ Cat'
super(Cat, self).__init__(talk)
if __name__ == '__main__':
tom = Cat()
</code></pre>
<p>输出:</p>
<pre><code>__init__ Cat
__init__ Animal: meow
</code></pre>
<hr/>
<p><em>编辑:</em></p>
<p>好吧,如果下面的方法不起作用,也许您的解释器中缓存了旧的类定义(尝试在新的解释器上运行它)。</p>
<pre><code>class Enemy(object):
def __init__(self, difficulty, power, MaxHP, magic, MaxMP, speed, name):
self.power = power + 2*difficulty
self.HP = self.MaxHP = MaxHP + 5*difficulty
self.magic = magic + 2* difficulty
self.MP = self.MaxMP = MaxMP + 5*difficulty
print 'Raaarghh!! I am the formidable {}.'.format(name)
class Goblin(Enemy):
def __init__(self, difficulty=1, power=1, MaxHP=5, magic=1, MaxMP=5, speed=5, name="Goblin"):
super(Goblin, self).__init__(difficulty, power, MaxHP, magic, MaxMP, speed, name)
if __name__ == '__main__':
g = Goblin(name='user1038783 goblin')
</code></pre>