How to rotate object based on roll,yaw and pitch values?

I am using 9 axis sensor, from that i am getting roll,yaw and pitch. i am getting these values to blender. now how can i rotate the object in blender using these values?

First, what IS a “9 axis sensor”? Are you talking about quaternion rotational outputs from the sensors? Are they Euler angles?

Ya they are Euler angles… 9 axis sensor means combination of accelerometer, gyrometer and magnetometer. Based on the output of these sensors we will do some calculation and we will get roll,yaw and pitch. http://www.starlino.com/imu_guide.html here you get proper explanation about 9 axis sensor.
i will get both quaternion rotational output(q.w,q.x,q.y,q.z) and Euler angles. i dont know which one is good to use and how to use. can you please help me out

Thank you very much for your replies… one final question is that, if apply roll,yaw and pitch to object either in bpy mode or bge mode both will be same right? because i am using bge mode and all the examples are in bpy mode.(sorry i am new to blender)

Not necessarily. bge is used for gaming mode, while bpy is used for most other purposes. Generally you want to use bge if you are planning on using your code for gaming and gaming-like applications, and bpy otherwise, and, there can be some serious differences. So it really depends on your goals, as to which you want to use. While there may be some cross-over, what can happen as you develop your program is that later on you could discover you have chosen the wrong mode and need to use the other. (voice of experience). I think there are a few things that can be done in a cross-over between the two modes, they are very tricky, and the best way is to make sure you choose the right mode to begin with.

As given in this link http://science-o-matics.com/2014/01/how-to-python-scripting-in-blender-8-rotation-mit-quaternionen/?lang=en i am trying to rotate the object using Quaternion, but i am stuck in the middle…

import bge
import math
import bge
import math
cont=bge.logic.getCurrentController()
obj=cont.owner
xyz = obj.localOrientation.to_euler()
value=[None]*3
while(1)
if sens.positive:
try:
line=ser.readline()
words=str(line,‘UTF8’)
words=str.split(words,“,”)
if len(words) >0:
value[0]=float(words[0])
value[1]=float(words[1])
value[2]=float(words[2])
xyz[0] = math.radians(value[1])
xyz[1] = math.radians(value[0])
xyz[2] = math.radians(value[2])

in the variable “value” i have roll, yaw and pitch… i don’t know how to apply this(roll,yaw and pitch) to object. can someone help in python scripting how i apply roll,yaw and pitch to object