Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the error of TypeError displaying string indices must be integers in python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to solve python TypeError display string indices must be integers error, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

An error was encountered in the project:

TypeError: because string indices must be integers is the returned interface data, I can't tell what is wrong for the moment, and then I restore the scenario: unicode_str = upright abcd`

Print unicode_str [2]

Print unicode_str ['mykey'] reads a non-existent attribute of a unicode-encoded string, see the third line, and then the above error occurs, so when reading a dictionary, it is best to determine the type first, and then check to see if it already has such an attribute:

Type (mydict) = = type ({}) # check not a dictionary if it is a dictionary, then see if there is such an attribute: mydict.has_key ('mykey')

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report