我有一个国际象棋程序的棋子类,我希望其他棋子可以继承:
class Piece:
def __init__(self, player, diag, straight, opponent, marker, unicode):
self.player = player
self.diag = diag
self.straight = straight
self.opponent = opponent
self.marker = marker
self.unicode = unicode
例如,国王类必须设置特定于其自身的属性,但必须是基类属性的一部分:
from Piece import Piece
class King(Piece):
def __init__(self, player, opposition, unicode):
super.__init__(player,False, False, opposition,"K", unicode)
self.has_moved = False
self.casle_king = True
self.castle_queen = True
我的问题是,即使我在片段中定义了它们,当我将它们传递给超函数时,它们也会引发意外的参数错误。
国王从Piece继承但设置它们共享不同的特定属性的正确方法是什么?
答案 0 :(得分:2)
您忘记了超级括号:
super().__init__(player,False, False, opposition,"K", unicode)
或者:
Piece.__init__(self, player,False, False, opposition,"K", unicode)