【发布时间】:2013-04-27 03:25:42
【问题描述】:
我正在开发一个自定义类来使用 Python 处理矩阵。我遇到了一个问题,我的测试程序显然没有向我的 setitem 方法传递足够的参数。代码如下:
def __setitem__(self, rowIndex, colIndex, newVal):
self.values[rowIndex][colIndex] = newVal
以及引发错误的测试代码:
M[0, 0] = 5.0; M[0, 1] = 7.0; M[0, 2] = -2.0;
M[1, 0] = 3.0; M[1, 1] = 6.0; M[1, 2] = 1.0;
M 在尝试设置项目之前调用 Matrix 的 init。
我收到了这个错误: TypeError: setitem() 只需要 4 个参数(给定 3 个) 谢谢!
【问题讨论】:
标签: python python-3.x