Script to copy all materials from one object to another, slot for slot. Looking for a way to copy materials from one object to another. so I have an object that I imported. a daz character to be specific. I have made shader for all of the materials. This character is now setup and ready to go. 
Now I have to import him multiple times into blender in different poses etc. so i am looking for a way to apply all the materials I have already made to the new import. Since the new import has the same material names as the old blender appends everything .001 so  I now have torso and torso.001 as available materials. So Im looking for a script which will go through all the material slots on the character and set the active material from the .001 to the original one. can anyone help me out here?
This is what I came up with. Select the object with the "wrong" materials first (like 'torso.001',...) and the object with the "original" materials last (like 'torso',...). Then run the script. It compares all material names and if one of the "wrong" materials starts with the name of one of the "right" materials, it will be replaced by this mat. (So the material 'torso.001' would be replaced by the material 'torso').

The script does not update the 3dView, so be sure to do some action (like zoom in, etc.) to update the viewport after you run the script!

Also this might not work correctly, if some names are combined of other names. E.g. if you have two materials 'torsoUpper' and 'torso'. If that is a problem, I can edit the script.

Hope this helps.

import bpy

c = bpy.context

# Select multiple objects. 
# The last selected should be the object with the "original" colors
# The script loops through all materials of the other objects and compares
# them to the materials of the "original" object. If their names start with the same
# letters, the material is replaced with the original.
# HINT: The script does not update the 3dView!

print("---RUNNING SCRIPT---")
src = c.active_object

for i in c.selected_objects:
    if (i == src):
        continue
    for src_id in range(len(src.data.materials)):
        for replace_id in range(len(i.data.materials)):
            src_name = src.data.materials[src_id].name
            rep_name = i.data.materials[replace_id].name

            if (rep_name.startswith(src_name)):
                i.data.materials[replace_id] = src.data.materials[src_id]
                print("Replaced "+rep_name+" by "+src_name)
                break