How to remove a modifier in 2.8?

I can successfully add a ‘REMESH’ modifier to a ‘cube’ object with the following code:

objectToSelect = bpy.data.objects[“cube”]
objectToSelect.select_set(True)
bpy.context.view_layer.objects.active = objectToSelect
bpy.ops.object.modifier_add(type=‘REMESH’)
bpy.ops.object.modifier_apply(apply_as=‘DATA’, modifier=“Remesh”)

Then I try to remove it with

ob = bpy.data.objects.get(“cube”)
bpy.ops.object.select_all(action=‘DESELECT’)
bpy.data.objects[‘dice_1’].select_set(True)
bpy.ops.object.modifier_remove(“Remesh”)

but it doesn’t go away. As I rerun the code in an animation, the number of ‘REMESH’ modifiers just keeps growing with each cycle through the animation?

Try

ob = bpy.data.objects.get("cube")
remesh_mods = [mod for mod in ob.modifiers if mod.type == 'REMESH']
if remesh_mods:
    ob.modifiers.remove(remesh_mods[-1])

Thanks Cirno! That did the trick.