Python error "TypeError: string indices must be integers, not str"
-
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 strLine 13 of the the code:
email_s.append(email_1["email_address"]) -
This should get you started…click HERE.
-
@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.
-
Please don’t answer strictly off-topic posts. It only encourages further off-topic postings.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login