Using python to change the settings of all subdivision surface modifiers I found this python script to add a subdivision surface modifier to all objects

import bpy

#Iterate over all members inside the Object struct
for ob in bpy.data.objects:
     #Check if object is a Mesh
     if ob.type == 'MESH':
         #Add a SUBSURF Modifier with the name "My SubDiv".
         ob.modifiers.new('My SubDiv', 'SUBSURF')


Is it possible to modify this so that it instead changes the view setting of all subdision surface modifiers?
Use the old one if it exists, else create new one.


Iterated over scene objects rather than all objects in blend.
If the object already has a modifier named "foo" use it, otherwise
create a new one.


test code

import bpy
context = bpy.context

for ob in context.scene.objects:
     if ob.type == 'MESH':
         # get old one or add one
         m = ob.modifiers.get("My SubDiv") or ob.modifiers.new('My SubDiv', 'SUBSURF')
         m.levels = 1
         m.render_levels = 2
         m.quality = 3


oh and in case in testing you have ended up with a cluster of modifiers, here is an example of removing all modifiers with a name starting with "My SubDiv".

for ob in context.scene.objects:
     if ob.type == 'MESH':
         mods = [m for m in ob.modifiers
                 if m.name.startswith("My SubDiv")]
         while mods:
             ob.modifiers.remove(mods.pop())