def group_move(group, damper):
# Make a copy to test values
new = group
# See what the original group value is
print("Test = " + str(group.ctris[0].p1.x))
dr = some float
dx = some float
dy = some float
# Make changes to new
moveGroup(new, dr, dx, dy)
# See if those changes produce allowed values
if (off_board_check(new) == 1):
damper += 2.0
# Reset to original to try again
print("Test Here = " + str(group.ctris[0].p1.x))
group_move(group, damper)
else:
# If everything is on the board, then make the change
group = new
If I run this, I will see that on the very first recursion, the Test print line produces a different value from the Test Here print line. Why? How is this code possibly affecting the values of group? I am trying to pass an unchanged group onto the next recursive level of group_move in the case that the test values failed, but it seems that group is somehow being affected before I even make any recursive calls. How is the above any different from this:
>>> x = 1
>>> y = x
>>> x = 7
>>> y = 77
>>> x
7
>>> y
77
The comment is incorrect. That does not make a copy. All that does is make a variable named
newpoint at the same object thatgroupis pointing at.If you want to create an actual copy, you may want to look at
copy.deepcopy().