How can I get a particular editor space in python? Right now, to set the current action before rendering, I am doing this to find the dopesheet editor space:

dope_sheet = None
for space in bpy.context.area.spaces:
    if space.type == 'DOPESHEET_EDITOR':
        dope_sheet = space
        break
else
    print('CANNOT FIND DOPESHEET_EDITOR IN bpy.context.area.spaces!!!')
    return


Is there some easier way to get the dopesheet editor than searching spaces for it?
Your code doesn't seem right, it should be

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'DOPESHEET_EDITOR':
        space_data = area.spaces.active
        break
else:
    space_data = None

if space_data is not None:
    pass


To avoid searching for the right area (which may or may not exist in current screen layout), it's possible to change bpy.context.area.type temporarily to the type you require.

However, I'm pretty sure what you actually want to do is:

bpy.context.object.animation_data.action = bpy.data.actions['The Name']