Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x Python数组迭代未按预期工作_Python 3.x - Fatal编程技术网

Python 3.x Python数组迭代未按预期工作

Python 3.x Python数组迭代未按预期工作,python-3.x,Python 3.x,使用调试控制台,我已经得到了我想要的“结果”。我是通过以下方式实现的: response.hits.hits[0]。\u source 所以我更进一步,决定创建一个循环: projection = [] for hit in response.hits: for subHit in hit.hits: projection.append(subHit._source) 但是现在我得到了一个异常声明,subHit没有hits属性。。。我很困惑 我做错了什么?看起来像您的响

使用调试控制台,我已经得到了我想要的“结果”。我是通过以下方式实现的:

response.hits.hits[0]。\u source

所以我更进一步,决定创建一个循环:

projection = []
for hit in response.hits:
    for subHit in hit.hits:
        projection.append(subHit._source)
但是现在我得到了一个异常声明,
subHit
没有
hits
属性。。。我很困惑


我做错了什么?

看起来像您的
响应。hits
不是数组,而是
响应。hits.hits
是数组。所以你一定是在做这样的事

for hit in response.hits.hits:
    projection.append(hit._source)


对于响应中的命中。hits.hits
第二次命中不是属性,而是对象