pythonj1939

Python converting UINT8


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


Solution

  • Turn it into a bytearray.

    >>> bytearray('abc')
    bytearray(b'abc')
    >>> bytearray('abc')[1]
    98