Error with code

Hi there, I modified an existing code to have selected objects first material selected in mesh edit mode, then grown for one unit and assigned that material. Sadly it doesn’t work properly, hope you guys can help. Being that this embarrassingly an easy code, I’m very ashamed that I’m asking for help online.

Here’s the code:

import bpy

for object in bpy.context.selected_objects:

bpy.context.scene.objects.active = o
if len(o.material_slots) > 1:
    
    o.active_material_index = 1
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.object.material_slot_select(action='SELECT')
    bpy.ops.mesh.select_more()
    bpy.ops.object.material_slot_assign()
    bpy.ops.object.mode_set(mode = 'OBJECT')

In the first line you give your object the name “object” and then you try to reference it using the name “o”.

Ok, thanks, I’ll try that.