How to move modifiers of multiple objects up or down? I would like to move a modifier (which I have already identified) to the bottom of the list of existing modifiers. Unfortunately it does not work and I don't get why...? However, if the object is active, it moves perfectly to the bottom:

#ob = my object, not necessarily it must be selected, it is found by a function
#smooth = #my modifier (found through a function)
for m in ob.modifiers:
    bpy.ops.object.modifier_move_down(modifier = smooth.name)


This only works if the active object is ob. Do I have to override the context? There is a similar question to this but I have no idea how to apply this in my case.



It seems that I have solved my problem by overriding the context members:

for m in ob.modifiers:
    c = {}
    c["object"] = c["active_object"] = ob
    bpy.ops.object.modifier_move_down(c ,modifier = smooth.name)


Any thoughts? Is there a better way of doing that?
Override the context by passing the actual object {'object': obj} to bpy.ops.object.modifier_move_up() or  bpy.ops.object.modifier_move_down() operator. 

Example on how to move all subdivision modifiers by name (they are usually called 'Subdivision') of multiple objects to the top (position 0) in the modifier stack:

C = bpy.context
mod_name = "Subdivision"

for obj in C.selected_editable_objects:
    # Test whether there is a modifier called "Subdivision" at all 
    if any(m for m in obj.modifiers if m.name == mod_name):
        # Iterate through all modifiers in reverse
        for mod in reversed(C.object.modifiers):
            # Move the modifier as long as its position is 0
            while obj.modifiers.find(mod_name) != 0:
                bpy.ops.object.modifier_move_up({'object': obj}, modifier=mod_name)


Related questions: 


Move modifier to the top of the stack through python?
How can I put a modifier at the top of the modifier stack?