是我的代码:Python的OOP初始化参数错误
class Board:
def __init__ (self, boardLength, boardHeight, pieces):
self.__boardLength = boardLength
self.__boardHeight = boardHeight
self.__pieces = pieces
self.__snapShots = []
self.__tiles = []
while len(self.__tiles) < (self.__boardHeight*self.__boardLength):
self.__tiles.append(0)
board1 = Board(5, 4,
[u,I_shape(1,'I'),X_shape(3,5,'U'),T_shape(4,5,'U'),L_shape(3,5,'U')]
)
,我得到这个:
TypeError: __init__() takes exactly 4 arguments (3 given)
据我所知,初始化坐4个arguements,但其中一人是自我,我把它另外三个。任何人都可以告诉我我做错了什么?
I_shape的'__init__'是什么?这是一个给出三个参数的调用(隐含的“自我”加上你给出的两个参数)。 – torek 2012-04-20 17:30:20
我不得不尝试修复这个代码格式,就像3次。它很难阅读。 – jdi 2012-04-20 17:31:56
您可能会忽略的是围绕TypeError的上下文的其余部分。这应该告诉你发生崩溃的确切位置,并且@Lattyware在答案中表明了它最可能出现在I_shape类中而不是这个Board类。 – jdi 2012-04-20 17:33:04