How can i get the change in value of an objects rotation between the current and previous frame, and use it in a driver
import bpy, copy

#get current frame
thisFrame = bpy.context.scene.frame_current

#go back one frame
bpy.context.scene.frame_set(thisFrame -1)


#get z rotation of current object
print ("rotation on frame")
print (bpy.context.scene.frame_current)
print (bpy.context.object.rotation_euler[2])

#set custom property ZrotLast to be the same as z rotation
last =copy.copy( bpy.context.object.rotation_euler)
bpy.context.object["ZrotLast"] = last[2]

#go back to current frame
bpy.context.scene.frame_set(thisFrame)

#set custom property ZrotCurrent to be the same as z rotation
bpy.context.object["ZrotCurrent"] = bpy.context.object.rotation_euler[2]

#get z rotation of current object
print ("rotation on frame")
print (bpy.context.scene.frame_current)
print (bpy.context.object.rotation_euler[2])

#work out difference between current and last frame
bpy.context.object["ZrotDelta"] = bpy.context.object["ZrotCurrent"] - bpy.context.object["ZrotLast"]


Please note DO NOT try changing bpy.context.scene.frame_current to change the frame! it will appear to work but it seems like nothing in the frame updates so you will get the same rotation information as the original frame, use bpy.context.scene.frame_set and it works correctly.