BPY how to detect what mode is the current mode in 3D View I'm writing a script, trying to save the current mode that the active object is in, Object Mode or Edit Mode, in order to reset the object to that mode after running the script. The issue I'm facing is that it's a toggle, so is there a way to detect this mode and save it to a variable?
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 )