Apply a modifier with python [duplicate]

I' ve written the following function to apply a shrinkwrap modifier

def shrinkwrap(obs):
for ob in obs:
if not ob.type == 'MESH':
continue
msw = ob.modifiers.new("shrink", type = 'SHRINKWRAP')
bpy.data.objects["body_2"].modifiers["shrink"].target = bpy.data.objects["body_1"]
bpy.ops.object.modifier_apply(apply_as = 'DATA')


I've problems with the last row (it is the function that should let me push the apply button shown in the following image )

In this image the target has not been selected, the function selects it correctly.

• Hello, what exactly is your question ? – Gorgious Sep 11 '20 at 15:32
• Yes, thank you :) – Carmine Buonagura Sep 11 '20 at 16:02