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
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
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