2

I have some canbus string data (unit8) like: data: [24, 4, 0, 0, 191, 9, 146, 9]

When I try to capture this data and print on the console it looks like ascii.

payload = [x for x in data.data]
print payload
>>>['\x00', '\x00', '\x00', '\x00', '\x02', '\x00', '\x00', '\x00']

How do I get this data back to: [24, 4, 0, 0, 191, 9, 146, 9]

Matt

Droter
  • 193
  • 1
  • 1
  • 8

1 Answers1

3

Turn it into a bytearray.

>>> bytearray('abc')
bytearray(b'abc')
>>> bytearray('abc')[1]
98
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Yes, that worked. I used payload = bytearray(data.data) then print [x for x in payload] it prints [24, 4, 0, 0, 191, 9, 146, 9] – Droter Sep 27 '15 at 20:32
  • @Droter if you feel that solved your problem, you should accept it as the correct answer. – Eugene K Sep 27 '15 at 20:45