Problems with changing material color

import bpy
from bpy import *
import Blender.Draw as Draw

#Retrieving the material of the selected object
mat = []
sce = data.scenes.active
ob = sce.objects.active
nmesh = ob.getData()
mat = nmesh.getMaterials()[0]
mat.setRGBCol(1.0,0.0,1.0)

This code works if the nmesh already has a material added to it,
but you must add the material manually. I have looked around, and
I have found the object.setMaterials() method. I can not seem
to find a working example of it being used, and I am also
not sure what to put into the method’s parameters. Thanks

Here’s a working example:

import bpy
from bpy import *

sce = data.scenes.active
ob = sce.objects.active
mesh = ob.getData(False,True)
mat = data.materials.new('myMaterial')
mat.setRGBCol(1.0,0.0,1.0)
mesh.materials=[mat]

Note that you still need to force a redraw to see things happening in the GUI.

thanks man