I am trying to add an object to a list but since I’m adding the actual object when I try to reset the list thereafter, all the values in the list are reset.
Is there an actual way how I can add a monitor object to the list and change the values and not affect the ones I’ve already saved in the list?
Thanks
Code:
arrayList = []
for x in allValues:
result = model(x)
arrayList.append(wM)
wM.reset()
where wM is a monitor class – which is being calculated / worked out in the model method
Is your problem similar to this:
If so, you simply need to copy the objects when you store them:
The objects in question should implement a
__copy__method to copy objects. See the documentation forcopy. You may also be interested incopy.deepcopy, which is there as well.EDIT: Here’s the problem:
You need to append a copy:
But I’m still confused as to where
wMis coming from. Won’t you just be copying the samewMobject over and over, except clearing it after the first time so all the rest will be empty? Or doesmodel()modify thewM(which sounds like a terrible design flaw to me)? And why are you throwing awayresult?