Use Context
So I am wanting to select this collection and delete it.
Further to Blender 2.80: Delete Collection or clear the intial scene in scripting mode
As is the case with most of blender making active in the UI gives it context.
The context collection can be the scene collection so don't want to delete that.
import bpy
from bpy import context
remove_collection_objects = True
coll = context.collection
scene = context.scene
if coll:
if remove_collection_objects:
obs = [o for o in coll.objects if o.users == 1]
while obs:
bpy.data.objects.remove(obs.pop())
if coll is not scene.collection:
bpy.data.collections.remove(coll)
Remove named collection and its unique objects
Script below will remove the default scene collection "Collection 1" and all objects within it.
Change name
to collection to remove and set the remove_collection_objects
toggle.
import bpy
#from bpy import context
name = "Collection 1"
remove_collection_objects = True
#coll = context.collection #
coll = bpy.data.collections.get(name)
if coll:
if remove_collection_objects:
obs = [o for o in coll.objects if o.users == 1]
while obs:
bpy.data.objects.remove(obs.pop())
bpy.data.collections.remove(coll)