Python object references quirk

Hi Python/Blender specialists,

Maybe I do not understand python. But to be able to restore the old camera orientation at the end of my program I was planning to us the object with name camera_rotation to store this old orientation. But strange thing is that now after setting the current camera orientation to another value (scene.camera.rotation_euler[0] = scene.camera.rotation_euler[0]-1) also the value of camera_rotation is changed?! Can anybody explain this behavior? Here below is the code with the output. So I expected the last printed value to be still -2.3490657806396484

scene = bpy.context.scene
# get the blender camera with camera_name we want to render the scene
scene.camera = bpy.data.objects[camera_name]
camera_rotation = scene.camera.rotation_euler
print(camera_rotation is scene.camera.rotation_euler)
print(camera_rotation[0] is scene.camera.rotation_euler[0])
print(camera_rotation[0])

scene.camera.rotation_euler[0] = scene.camera.rotation_euler[0]-1
print(camera_rotation is scene.camera.rotation_euler)
print(camera_rotation[0] is scene.camera.rotation_euler[0])
print(camera_rotation[0])

I get this as output:
False
False
-2.3490657806396484
False
False
-3.3490657806396484

Gr,
Michiel

I believe you need to force a depsgraph update after updating transforms before you’ll see reliable output:
https://docs.blender.org/api/current/info_gotcha.html#no-updates-after-setting-values

By default a reference is created.
Make a copy instead:

camera_rotation = scene.camera.rotation_euler.copy()

Thanx for the quick answer. But I thought if the id’s of objects are not the same the copy is already done implicitly. To proof the id’s are different I checked with the “is”-statement if that was the case. And indeed in the oitput you see " False".

Do you have an explanation for this?

Michiel