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
第二次命中不是属性,而是对象