Python OOP init参数错误

1 python oop initialization

所以这是我的代码:

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')]
)
Run Code Online (Sandbox Code Playgroud)

我明白了

TypeError: __init__() takes exactly 4 arguments (3 given)
Run Code Online (Sandbox Code Playgroud)

我知道init有4个争论,但其中一个是自我,我给了另外三个.谁能告诉我我做错了什么?

Gar*_*tty 6

我想你的问题实际上是在I_shape,因为你的其他形状都需要3个参数.我运行它,它工作正常,替换不存在的类None.

此外,值得注意的__variable是,99.9%的时间不需要使用名称修改().如果要表明它是私有的,请使用单个下划线.