Community
    • Login

    Python error "TypeError: string indices must be integers, not str"

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 3 Posters 3.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rohit bhatR
      Rohit bhat
      last edited by

      My friend who has a little bit knowledge about machine learning was getting the following python error:

       File "em_sep.py", line 13, in <module>
      
          if ema_1["confidence_score"] == "50":
      
      TypeError: string indices must be integers, not str
      

      Line 13 of the the code:

      email_s.append(email_1["email_address"])
      
      Alan KilbornA markfilanM 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Rohit bhat
        last edited by

        @Rohit-bhat

        This should get you started…click HERE.

        1 Reply Last reply Reply Quote 2
        • markfilanM
          markfilan @Rohit bhat
          last edited by

          @rohit-bhat said in Python error "TypeError: string indices must be integers, not str":

          TypeError: string indices must be integers, not str

          TypeError: means that you are trying to perform an operation on a value whose type is not compatible with that operation. An Iterable is a collection of elements that can be accessed sequentially . In Python, iterable objects are indexed using numbers . When you try to access an iterable object using a string or a float as the index, an error will be returned as TypeError: string indices must be integers. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value.

          For example, str[hello"] and str[2.1] as indexes. As these are not integers, a TypeError exception is raised. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value . If you are accessing items from a dictionary , make sure that you are accessing the dictionary itself and not a key in the dictionary.

          Python supports slice notation for any sequential data type like lists, strings , tuples, bytes, bytearrays, and ranges. When working with strings and slice notation, it can happen that a TypeError: string indices must be integers is raised, pointing out that the indices must be integers, even if they obviously are.

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @markfilan
            last edited by

            @markfilan

            Please don’t answer strictly off-topic posts. It only encourages further off-topic postings.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors