How to parent two objects in python How to parent two object without selecting them manually in blender python scripting console? I want parent object which stored in variable like

Add a cube at the origin:

a=bpy.ops.mesh.primitive_cube_add()


Create an empty object:

b=bpy.ops.object.empty_add(type="SPHERE")


How to parent a to b?
bpy.ops.mesh.primitive_cube_add()
a = bpy.context.object
bpy.ops.object.empty_add(type="SPHERE")
b = bpy.context.object
const = b.constraints.new(type='CHILD_OF')
const.target = a