for multi in json_file["shapes"]: TypeError: list indices must be integers or slices, not str
时间: 2023-08-25 07:18:15 浏览: 161
Python BeautifulSoup [解决方法] TypeError: list indices must be integers or slices, not str
5星 · 资源好评率100%
这个错误是因为在for循环中使用了错误的索引类型导致的。根据您提供的代码,错误发生在使用json_file["shapes"]这个列表时,而使用非整数或切片作为索引会导致TypeError: list indices must be integers or slices, not str的错误。为了解决这个问题,您需要确保在for循环中使用整数或切片作为索引。您可以修改代码如下:
```python
for multi in range(len(json_file["shapes"])):
# 这里是您的循环体
```
这样,您就可以使用整数索引来遍历json_file["shapes"]列表中的元素了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [已解决TypeError:List indices must be integers or slices , not str](https://blog.csdn.net/yuan2019035055/article/details/126149910)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [TypeError: list indices must be integers or slices, not tuple](https://blog.csdn.net/m0_70484757/article/details/131177799)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文