Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 05:53:15 10月01日 Update

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.

Tags: Error dictionary attribute help clarity content scene character string this interface data article novice time more best knowledge type coding Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Apple vpn Shulou Technology Docker