Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';int';对象没有属性'__获取项目';_Python_Runtime Error - Fatal编程技术网

Python ';int';对象没有属性'__获取项目';

Python ';int';对象没有属性'__获取项目';,python,runtime-error,Python,Runtime Error,我只是python的初学者,即使在网上搜索,我也无法纠正这一点。一些问题: File "C:\Python27\winculum.py", line 33, in coll self.col[i][j] = self.result TypeError: 'int' object has no attribute '__getitem__' 应该是: for i in range[6]: for j in range[6]: 错误: range(6) 表示您正

我只是python的初学者,即使在网上搜索,我也无法纠正这一点。

一些问题:

File "C:\Python27\winculum.py", line 33, in coll
    self.col[i][j] = self.result
TypeError: 'int' object has no attribute '__getitem__'
应该是:

for i in range[6]:
            for j in range[6]:
错误:

range(6)
表示您正试图对int而不是列表应用索引运算符
[]
。所以,
col
不是一个列表,即使它应该是?让我们从那开始

看这里:

'int' object has no attribute '__getitem__'

在内部使用不同的变量名,看起来列表会在迭代期间覆盖
col
变量。(设置
列时,不是在迭代过程中,而是在下面的迭代过程中。)

此错误可能表示先前代码中使用了同名变量,但用于其他目的。可能,变量的名称与代码后面使用的现有函数一致。

您也可以先将int转换为str,然后为其分配索引,然后再将其转换为int 像这样:

col = [[0 for col in range(5)] for row in range(6)]

我最近在处理递归和嵌套列表时遇到了类似的问题。 我宣布:

int(str(x)[n]) //where x is an integer value
而不是

print(r_sum([1,2,3[1,2,3],]))

注意数字3后面的逗号

这是很多代码。无论如何,这里的问题是,您在列表理解中使用了
col
作为迭代器,它与外部
col
在同一范围内,因此它覆盖了它。只需将理解中的
col
更改为其他内容即可。嗨!!谢谢你的宝贵建议。。它对汉克斯的建议起了作用。。。你能告诉我如何给一个变量分配double的最大值吗
print(r_sum([1,2,3[1,2,3],]))
print(r_sum([1,2,3,[1,2,3],]))