I noticed a very strange behavior when working with python that binds 2 variables, that are set equal, to the same changes and I want to know if anyone has an explanation for this behavior and if there is a better solution than mine for it.
For example, I have an array called schema1. I later need to expand schema1 with a new set of variables but I can't mess up the original array so I create schema2 by setting it equal to schema1 like so:
from someFileICreated import SomeClass
schema1 = SomeClass.SomeSchema
Suppose schema1 has array [a, b, c], then I:
schema2 = schema1
schema2.append(d, e, f)
Now, schema2 should have [a, b, c, d, e, f] However, for some reason, schema1 also has [a, b, c, d, e, f]
I don't understand this behavior, so if you have an explanation that would be great. As far as solutions go, this will work, but I'm wondering if there is another way that is better and can avoid a loop.
Instead of setting schema2 = schema1 I just do this:
schema2 = []
for x in schema1:
schema2.append(x)