Python 类型错误 : 'int' object is not iterable

标签 python

下面的代码给我错误 Python

类型错误:“int”对象不可迭代:

代码:

hosts = 2
AppendMat = []
Mat = np.zeros((hosts,hosts))
Mat[1][0] = 5
for i in hosts:
    for j in hosts:
        if Mat[i][j]>0 and Timer[i][j]>=5:
            AppendMat.append(i)

我该如何修复错误 -

TypeError: 'int' object is not iterable?

其次,如果 if 条件为真,我如何附加 i 和 j 的值?在这里,我试图仅附加 i。

最佳答案

试试这个:

for i in xrange(hosts):

关于Python 类型错误 : 'int' object is not iterable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18595695/

相关文章:

python - AttributeError 'tuple' 对象没有属性 'get'

python - 如何使用正则表达式从字符串中提取数字并返回最后 3 个或更少的数字

python - 使用 docopt 解析时,如何使用存储在数组中的未知 n 个值来创建参数

Python:使用 numpy 保存/加载大数组

python - 在虚拟环境中运行 Spyder 最简单的方法是什么?

python - 如何让queue.get尽快返回

python - 组织 Python 库和文件夹

python - 在 Python 脚本中循环执行 awk

Python 嵌套列表加入查找引用列表

python - 如何将类装饰器与pickle一起使用?