I need to have several objects that each one has an individual array. I have written this code:
read_values = list()
for read_unit in read_units:
read_value = ReadValues.objects.all().filter(ReadID=read_unit.ReadID)
element = TempObjectForReadValues()
for read_element in read_value:
element.read_elements[read_element.Code] = read_element.ReadValue
read_values.append(element)
print(element.read_elements)
print(' ')
for test_element in read_values:
print(test_element.read_elements)
And this is how I defined the class:
class TempObjectForReadValues():
read_elements = [None] * 10
The result is:
[None, None, 16.0, None, 189.0, 345.0, None, None, None, None]
[None, None, 16.0, 43.0, 876.0, 345.0, None, None, None, None]
[None, None, 16.0, 43.0, 876.0, 345.0, None, None, None, None]
[None, None, 16.0, 43.0, 876.0, 345.0, None, None, None, None]
That means the data are overwritten on the previous ones. Also if I do not assign anything to the array in new object, it holds the results from previous one. :(
How can I fix it?