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
如果我运行它,我会看到在第一次递归时,Test
打印行产生的值与Test Here
打印行不同。为什么?此代码如何可能影响 的值group
?在测试值失败的情况下,我试图将未更改的内容传递group
到下一个递归级别group_move
,但似乎group
在我进行任何递归调用之前就受到了影响。以上与此有何不同:
>>> x = 1
>>> y = x
>>> x = 7
>>> y = 77
>>> x
7
>>> y
77