How do I change actions in python I want to copy the world positions of a first bone to a second bone then save the second bones position as a keyframe(when the first bone has a keyframe) to retroactively fix rigging errors with roll on ik bones.

I can't sample the fcurves as they are local space so instead want to iterate the actions and set the frame then grab the matrix to apply and keyframe the second bone but can't find the command to set the action.
All actions in the file are saved in bpy.data.actions

for a in bpy.data.actions:
    print(a.name)


The action associated directly with your object, the one I'd call "in the slot"

action = object.animation_data.action


To set it to another action named "anotheraction"

object.animation_data.action = bpy.data.actions.get("anotheraction")


If there is no action named anotheraction it will set it to None.  If there is no animation data on the object you will need to call

object.animation_data_create()


beforehand.

Note: can also have actions on any strip in the strips collection of an nla track in the animation_data.nla_tracks collection of your object.