How do you script batch changes to bone constraints I need to understand how to script a batch change to bone constraints like copy location, limit distance etc.

I have a couple of hundred bones, with a set of constraints on them. It took forever to set up and I need to tweak them. 

A friend who has written scripts for me before gave me a solution to one problem. I've tried adjusting the code he wrote to do something else but I've written something wrong. I don't know the syntax and proper context.

I tried changing my friend's code in the text editor:

import bpy

armature = "Armature.001"

arm = bpy.data.armatures[armature]


for bone in bpy.context.object.pose.bones:
    bpy.ops.pose.select_all(action='DESELECT')
    bone.bone.select = True
    arm.bones.active = bone.bone

for constraint in bpy.context.active_pose_bone.constraints:
    print (constraint)
   if "Copy YZ only" in constraint.name:
        CopyLocationConstraint.use_y = True


bpy.ops.pose.select_all(action='SELECT')


I understand what this SHOULD do but don't see the relevance of some of these lines of code. I need some assistance to find what I am missing.

The next bit I need to change is a distance value on transformation constraints (to_max_y = 2cm?). I guess the solution is similar but I need to learn how to word changes like this correctly.

I've spent hours reading examples online but still need help.
I'd go about it this way.  I use context = bpy.context on test scripts, that can later be pasted into Operator or Panel code.  Work from the context object, rather than using a name like "Armature.001" (guilty myself on many occasions)

I use list comprehension out of preference. 

import bpy
context = bpy.context
# the rig object
rig = context.object

# all copy location constraints on all pose bones
constraints = [c for pb in rig.pose.bones 
                 for c in pb.constraints
                 if c.type == 'COPY_LOCATION'
               # and "XY" in c.name
              ]

# set the desired properties
for c in constraints:
    c.use_y = True

# similarly for Transformation
# type from mousing over add constraint in UI
constraints = [c for pb in rig.pose.bones 
                 for c in pb.constraints
                 if c.type == 'TRANSFORM'
              ]

for tc in constraints:
    tc.to_max_y = 0.02 # given 1 blender unit is 1m


# all constraints from preselected pose bones
constraints = [c for pb in context.selected_pose_bones 
                 for c in pb.constraints
              ]