You normally do this sort of thing with a for loop; using bpy.context.selected_objects
. That's a list of all of the objects you have selected.
Here's an example:
import bpy
for object in bpy.context.selected_objects:
print(object.name)
object.select_set(False)
object.hide_select = True
This isn't exactly what you asked for. the 4th line object.select_set(False)
also deselects the objects you are marking as hidden from selection. If you want to leave them selected, then leave that line out.
The reason this works and the code you posted doesn't is that your posted code is indented improperly. Properly indent the last line to make it part of the for loop
Properly indented your code would like like this:
import bpy
SEL_OBJS = bpy.context.selected_objects
ACT_OBJ = bpy.context.active_object
for OBJS in SEL_OBJS:
bpy.context.object.hide_select = True