Scripting: How to change objects mode and then revert back to previous mode
I don't know that is this: bpy.ops.object.mode current mode is here: bpy.context.mode

Save current mode:

returnto=False
if(context.mode!='OBJECT'):
    returnto=context.mode


Return to edit mode:

if(returnto):
    bpy.ops.object.mode_set(mode=returnto)


bpy.context.mode