Accessing UV Maps

I’m trying to create a script that will delete any UV maps named “UVMap”. In the info window, I see that the following method is used:


bpy.context.object.data.active_index = 0
bpy.ops.mesh.uv_texture_remove()

It looks like the active_index method is used also in Vertex Colors, so this is not specific to only UV Maps. How can I access the UV Map by name?

One way would be to do it through the object’s data, and test for the map by name:


obj = bpy.context.scene.objects.active
if "UVMap" in obj.data.uv_textures:
    bpy.ops.mesh.uv_texture_remove()