Cannot find camera after deleting and appending a new one with python I run a background script that:


deletes everything: 


override = {'selected_bases': list(bpy.context.scene.object_bases)}
    bpy.ops.object.delete(override)


appends a camera, a mesh and a light as object to the scene from a blend file:

with bpy.data.libraries.load(filepath) as (data_from, data_to):
    data_to.objects = data_from.objects
    print ("Objects added for map "+selectedmap+": " +str(data_to.objects))
sets the appended camera for the scene: 


bpy.context.scene.camera = bpy.data.objects['Camera']


adds a bunch of cylinders
does a render of the objects in the blend file
saves the file: 


bpy.ops.wm.save_mainfile(filepath=basepath + 'FPSPath.blend', check_existing=False)


then repeats again from, delete all
append another camera, mesh and light from a different blend file
render all again, but at this point the new camera does not seem to be selected as active, I do a bpy.context.scene.camera = bpy.data.objects['Camera'] after appending but, the render keeps coming back empty.


My print debug shows that the camera is changing name, (as camera.001 and so on) could that be the reason I am not getting anything on the render, is there a way to get any camera and then make it the active one?

Also the last blend file saved does not contain the camera, light or mesh objects I appended, should I add something else to the appending method? does it need anything else, the mesh object is never on the render, and only the first camera works.

Thanks.
If the new camera is getting named Camera.001 then it is likely that the old camera is not being deleted, as blender appends .XXX (where XXX is some number) when the requested name is already in use. I'm not to familiar with all the python delete functions, but this could be because that data isn't actually deleted until the scene is saved and re-opened, due to how blender manages garbage collection/scene data. 

You probably need to update your script to get the name of the new camera from ti after creation or assign a unique name to it when you create it, and the use that to set the active camera