python提示错误TypeError: 'dict_keys' object does not support indexing
生活随笔
收集整理的這篇文章主要介紹了
python提示错误TypeError: 'dict_keys' object does not support indexing
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python提示錯誤TypeError: 'dict_keys' object does not support indexing
原因:python2與python3之間的差異
python2中形如myTree.keys()[0]這樣的寫法是沒有問題的,因為myTree.keys()返回的是一個list;
而在python3中myTree.key()返回的則是dick_keys類型,故而出錯
解決方法:
將myTree.keys()[0]改為list(myTree.keys())[0]
總結
以上是生活随笔為你收集整理的python提示错误TypeError: 'dict_keys' object does not support indexing的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: xx = [example[x] for
- 下一篇: python 提示错误Attribute