copy material with python I copy one object in Blender with python。but when I change the old object's color , the new object's color also change. I know that because the new object and the old object have the same material。my way is that：

obj = bpy.data.objects[old_object_name]
mesh = obj.data
new_obj = bpy.data.objects.new(name, mesh)
bpy.context.scene.objects.link(new_obj)
bpy.ops.object.make_single_user(object = True, obdata = True, material = True,texture = True )


I want to Separate the new object's material and the old object's material.when I change one object's color ,another object's color doesn't change. but my way doesn't work.
Material.copy() is what you want. Also you have to duplicate the object's mesh because materials link to the object's data by default.

import bpy

scn = bpy.context.scene
obj = bpy.context.active_object
mat = obj.active_material
mesh = obj.data

dup = bpy.data.objects.new(obj.name, mesh.copy())
dup.active_material = mat.copy()
scn.objects.link(dup)

dup.location.x += 3    # just for clarity