Python run error in Text Editor but right in console

hello,I want to use python to add modifer(boolean). but when i test the python, i got an error:
the script is that:

1 import bpy
2 class Merge:
3 ‘’‘Merge mesh together’’’
4 def join(obj1,obj2):
5 bpy.ops.object.select_all(action=“DESELECT”)
6 obj1.select=True
7 bpy.ops.object.modifier_add(type=‘BOOLEAN’)
8 bpy.context.object.modifiers[“Boolean”].operation = ‘UNION’
9 bpy.context.object.modifiers[“Boolean”].object = obj2
10 bpy.context.object.modifier_apply(apply_as=‘DATA’, modifier=“Boolean”)
11 bpy.ops.object.select_all(action=“DESELECT”)
12 obj2.select=True
13 bpy.ops.object.delete(use_global=False)
14 Merge.join(bpy.data.objects[“Cube”],bpy.data.objects[“Cube.001”])

the error is on line 10,AttributeError: ‘Object’ object has no attribute ‘modifier_apply’.
Modifier was added on Cube,if I click the ‘Apply’ button of modifier, the Info show command:
bpy.context.object.modifier_apply(apply_as=‘DATA’, modifier=“Boolean”)

I want to known that why the text run will failed? is there any command need to be run ?
also,if I changed the script like that:

1 import bpy
2 class Merge:
3 ‘’‘Merge mesh together’’’
4 def join(obj1,obj2):
5 bpy.ops.object.select_all(action=“DESELECT”)
6 obj1.select=True
7 bpy.ops.object.modifier_add(type=‘BOOLEAN’)
8 obj1.modifiers[“Boolean”].operation = ‘UNION’
9 obj1.modifiers[“Boolean”].object = obj2
10 obj1modifier_apply(apply_as=‘DATA’, modifier=“Boolean”)
11 bpy.ops.object.select_all(action=“DESELECT”)
12 obj2.select=True
13 bpy.ops.object.delete(use_global=False)
14 Merge.join(bpy.data.objects[“Cube”],bpy.data.objects[“Cube.001”])

the error will be in line 8: KeyError: ‘bpy_prop_collection[key]: key “Boolean” not found’.


can you upload sample file so we can test it quickly !

thanks
happy bl