Closed jp-fizzbee closed 3 months ago
Usage:
Color = enum('RED', 'YELLOW', 'GREEN') action Init: # Define a record nested = record(a=1, b=[2, 3]) msg = record(node=5, color=Color.RED, message='Hello', nested=nested) msg2 = msg msg3 = deepcopy(msg) print("orig", msg, msg2, msg3) msg.color = Color.GREEN msg.nested.a = -1 msg.nested.b[0] = -2 print("after", msg, msg2, msg3)
Limitations:
action Init: arr = [2, 3] m1 = record(arr1=arr, arr2=arr) m2 = deepcopy(m1) print("orig", m1, m2) m1.arr1[0] = -4 m2.arr1[0] = -3 print("after", m1, m2)
In the original, m1.arr1 and m1.arr2 points to the same array. So changing arr1 changes arr2 as well. But in the deepcopy, m2.arr1 and m2.arr2 DO NOT point to the same array, so changing arr1 doesn't change arr2.
Usage:
Limitations:
In the original, m1.arr1 and m1.arr2 points to the same array. So changing arr1 changes arr2 as well. But in the deepcopy, m2.arr1 and m2.arr2 DO NOT point to the same array, so changing arr1 doesn't change arr2.