I have a class called "data-packet" shown below. I am trying to instantiate it so that I can use the values returned by the methods getAcc and getRot. I have also included the code that is creating an instance of the data_packet class in "main"
I am getting this error:
Traceback (most recent call last)
mydata = data_packet()
TypeError: __init__() takes exactly 2 arguments (1 given)
My assumption is that the instance is passing mydata to the argument called self, but nothing is being passed to l. If I am correct, how can I solve this error?
class data_packet (object):
def __init__(self, l):
self.data = [0,0,0,0,0,0,0,0,0]
self.type = ord(l[2])
if self.type == 0: # accel
self.data[0] = four_bytes(l[3],l[4],l[5],l[6]) * 1.0 / (1<<16)
self.data[1] = four_bytes(l[7],l[8],l[9],l[10]) * 1.0 / (1<<16)
self.data[2] = four_bytes(l[11],l[12],l[13],l[14]) * 1.0 /(1<<16)
elif self.type == 6: # heading
self.data[0] = four_bytes(l[3],l[4],l[5],l[6]) * 1.0 / (1<<16)
else: # unsupported
pass
def display(self):
if self.type == 0:
print 'accel: %7.3f %7.3f %7.3f' % \
(self.data[0], self.data[1], self.data[2])
elif self.type == 6:
print 'heading: %7.4f' % self.data[0]
else:
print 'what?'
def getAcc(self):
while self.type == 0:
.....dosomethings....
return accelData
def getRot(self):
while self.type == 5:
..... dosomethings....
return rotData
def main():
mydata = data_packet()
mydata.getAcc()
mydata.getRot()
print "********* : ", mydata.getAcc()
if __name__ == "__main__":
main()
lin the instantiation. Why is that confusing?lbeing an iterable.