I am trying to modify data in a 2 dimensional matrix (represented by a sequence of smaller sequences) in python. The matrix values are first initialized to "0.0" (shown as "current" in code below). I have a second 2 dimensional matrix that contains the actual data points, however, these data points are represented by ".", "C", and "H". I have written the code below to basically translate these characters into the proper values, but I'm running into an error "str object does not support item assignment". I know strings are immutable, but I'm not changing individual characters of a string, I'm removing the whole string. Here is the code:
for rline in range(len(lineAppend)):
for cline in range(len(lineAppend)):
if lineAppend[rline][cline]==".":
#print "is dot"
lineAppend[rline][cline] == 0.0
#lineAppend.remove(".")
#ineAppend.insert("0.0")
elif lineAppend[rline][cline]=="C":
lineAppend[rline][cline] == 25.0
elif lineAppend[rline][cline]=="H":
lineAppend[rline][cline] == 100.0
lineAppend is a matrix that is filled by reading a text file. It simply reads each line and saves it as a sequence. I am trying to change individual indexes to the above values, but I keep running into the error that occurs because strings are immutable. Is there any other way to modify the data to the desired values?
Here is the traceback:
Traceback (most recent call last):
File "/home/Desktop/python_projects/temp.py", line 172, in <module>
main()
File "/home/Desktop/python_projects/temp.py", line 169, in main
read_config("plate.txt")
File "/home/Desktop/python_projects/temp.py", line 110, in read_config
if lineAppend[rline][cline]==".":
TypeError: list indices must be integers, not str