BPY how to detect what mode is the current mode in 3D View
To store the mode which the active object is in you can use:

current_mode = bpy.context.object.mode


to store the mode in the variable current_mode. In order to set that mode again use the following line:

bpy.ops.object.mode_set ( mode = current_mode )