How to write drivers to be copied and pasted between objects' modifiers?
The id_data property of any object returns an ID object

Simple example adding a driver to the count of an array modifier  The modifier is on the default cube.



The driver script, prints out self,  self.id_data the path from self.id_data to self and returns 2.

import bpy

def test(self):
    print(self)
    print(self.id_data)
    print(self.path_from_id())
    return 2

bpy.app.driver_namespace["test"] = test


Here is the output to console

&lt;bpy_struct, ArrayModifier("Array")&gt;
&lt;bpy_struct, Object("Cube")&gt;
modifiers["Array"]


Hence other properties of the modifier can be accessed using self.other_modifier_property and properties of the object it is on via self.id_data.some_object_property

The driver UI deals in ID objects, as does the datapath used by fcurves etc.  You select the (ID) bpy.types.Object instance the modifier is on, and add the datapath from ID object to modifier. In this case self = self.id_data.modifiers["Array"]