Select object and recalculate normals via script? I have a script that allows to import and export .obj files which is working fine. However, I'd like to perform some operations in between these calls, for example select the mesh and recalculate the normals (outside). If I try that, I get a context error and I'm not sure why...?

RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect

    bpy.ops.import_scene.obj(filepath=source_to_file)
    
    print(&quot;Starting--------------------------------------------&quot;)
    for obj in bpy.data.objects:
        bpy.context.scene.objects.active = obj
        # go edit mode
        bpy.ops.object.mode_set(mode='EDIT')
        # select al faces
        bpy.ops.mesh.select_all(action='SELECT')
        # recalculate outside normals 
        bpy.ops.mesh.normals_make_consistent(inside=False)
        # go object mode again
        bpy.ops.object.editmode_toggle()
    print(&quot;Ending--------------------------------------------&quot;)
    
    bpy.ops.export_scene.obj(filepath=target_to_file,use_materials=True)

How is it possible to know the object imported by any operator (there is no return value) and how can I recalculate the normals per object that is triggered by a button?
Making normals outside can also be done with the bmesh module operator recalc_face_normals(bm, faces)
Sample script
import bpy
import bmesh

from bpy import context

#bpy.ops.import_scene.obj(filepath=source_to_file)
bm = bmesh.new()
meshes = set(o.data for o in context.selected_objects
            if o.type == 'MESH')
for mesh in meshes:
    bm.from_mesh(mesh)
    bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
    bm.to_mesh(mesh)
    bm.clear()
    mesh.update()
    
bm.free()
#bpy.ops.export_scene.obj(filepath=target_to_file, use_materials=True)

Saves the need to flip mode and context object.