TypeError: 'Book' object does not support indexing
时间: 2023-12-26 10:06:29 浏览: 240
引用\[1\]中提到,"TypeError: 'dict_keys' object does not support indexing"错误是因为Python 3以后的版本改变了dict.keys的返回值,返回的是dict_keys对象,不支持索引值。\[1\]而引用\[2\]中指出,在Python 3中,dict.values()(以及dict.keys()和dict.items())返回的是一个视图对象,而不是一个列表。为了解决这个问题,可以将返回的对象强制转换为list对象,如引用\[3\]所示。所以,对于你提到的"TypeError: 'Book' object does not support indexing"错误,可能是因为你在尝试对一个Book对象进行索引操作,而Book对象不支持索引。如果你想对一个对象进行索引操作,你需要确保这个对象是一个可索引的类型,比如列表或字符串。
#### 引用[.reference_title]
- *1* *3* [解决Python中字典出现“TypeError: 'dict_keys' object does not support indexing”错误](https://blog.csdn.net/Sophia_11/article/details/85173558)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [【python】错误TypeError: ‘dict_values‘ object does not support indexing when的改出](https://blog.csdn.net/gongdiwudu/article/details/130312098)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文