save avi files in blender using python script
bpy.context.scene.render.filepath contains the filename that the render will be saved to, you can change this and then use bpy.ops.render.render(animation=True) to render the animation to the specified file.

import bpy
bpy.context.active_object.material_slots[0].material = bpy.data.materials['Red']
bpy.context.scene.render.filepath = '//red.avi'
bpy.ops.render.render(animation=True)

bpy.context.active_object.material_slots[0].material = bpy.data.materials['Blue']
bpy.context.scene.render.filepath = '//blue.avi'
bpy.ops.render.render(animation=True)


The // at the beginning of the filename puts the file in the same folder as the blend file.