Python Forum
'str' object does not support item assignment
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'str' object does not support item assignment
#1
So currently i am experiencing an issue where i am trying to assign a value in a dictionary to an index value of a string


The code goes as follows


    searchValues = ['name', 'fame', 'game']
    values = {}

    versions = 5
    for v in range(1, versions+1):
         for value in searchValues:
             receivedValue = customFindFunction("{0}{1}".format(value, v), source)
             if (receivedValue is None):   #the find function returns None if it cant find the value specified
                 receivedValue = customFindfunction(value, source)
                 values[value] = receivedValue
                 continue
             valueKey = value + str(v)
             values[valueKey] = receivedValue  # ERROR OCCURS HERE, the receivedValue is "5"
The custom find function just searches a source string for a key (the value) and returns the actual value of the key (eg: string has Name : John, located in it, the function returns John, or None if it cant find the key)

Whenever the value is returned as None the first time, and it finds a value based on just a searchvalue, it enters into the values dict just fine

Whenever it finds the value on the first try and tries to enter a value into the values dict as values[value+v] it returns an error of "TypeError: 'str' object does not support item assignment"

This isnt the actual code, as the real code has quite a few other things going on during this that do not effect the code that is failing, so i left it out. The code functions fully and returns appropriate values when it finds a value based on its name eg: it finds "name" or "fame", but when it finds a value based on the value name plus a version number eg: "name1" or "fame1" it errors out
Reply


Messages In This Thread
'str' object does not support item assignment - by SolaVitae - Jul-28-2017, 03:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove an item from a list contained in another item in python CompleteNewb 19 6,210 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  'int' object does not support item assignment shane1236 5 8,043 Aug-13-2019, 01:53 PM
Last Post: buran
  Error: int object does not support item assignment ankita_nthu 2 14,171 Jul-07-2019, 02:14 PM
Last Post: ankita_nthu
  How do I use this? TypeError: 'NoneType' object does not support item assignment ejected 9 22,691 Mar-26-2019, 05:06 AM
Last Post: ejected
  ValueError: This COM object does not support events. meenakshi11 0 4,041 Mar-08-2018, 09:42 AM
Last Post: meenakshi11

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020