您好我找不到这个问题的答案,所以我会在这里问一下。
我试图调用两个家长课程的 init 功能,但我真的不知道如何在语法方面做到这一点。
以下是课程
from IsVisible import *
class Shape(IsVisible):
def __init__(self):
super(Shape, self).__init__()
self.posSize = []
def getPosSize(self):
return self.posSize
class Rectangle(Shape):
def __init__(self):
super(Rectangle, self).__init__()
self.color = self.blue
self.posSize = [20,50,100,100]
class Movable:
def __init__(self, fps):
self.deltaX = self.__xStartSpeedPerSec/fps
self.deltaY = self.__yStartSpeedPerSec/fps
__xStartSpeedPerSec = 0.0
__yStartSpeedPerSec = 0.0
class Mob(Rectangle, Movable):
def __init__(self, fps):
super(Mob, self).__init__()
super(Mob, self).__init__(fps)
所以Mob类是这里的孩子,父母是Shape和Movable。我想从Mob的 init 函数中调用Shape和Movable的 init ()函数。但是我目前使用super执行此操作并不起作用。 我得到错误:
super(Mob, self).__init__(fps)
TypeError: __init__() takes exactly 1 argument (2 given)
所以,我的问题是。当他们拥有不同数量的参数时,如何调用两个父母的 init 方法?