所以这是我的代码:
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)
我知道init有4个争论,但其中一个是自我,我给了另外三个。谁能告诉我我做错了什么?
答案 0 :(得分:6)
我想你的问题实际上在I_shape
,因为你的其他形状都需要3个参数。我运行它并且工作正常,用None
替换了不存在的类。
此外,值得注意的是99.9%的时间不需要使用名称修改(__variable
)。如果要表明它是私有的,请使用单个下划线。