0

I have a list of bytes i created by using struct.pack() in python to pack integers and floats from a python dictionary into bytes:

current_list: [b'\xd3\xb6\x00\x00', b'\x80\x82efre\x84\x00', b'\x01', b'\x03', b'\x00\x00', b'\x0b\x04', b'\xd8\xff']

I now want to create an array of all the individual bytes like so:

list_i_want: [b'\xd3', b'\xb6', b'\x00', b'\x00', b'\x80', b'\x82', b'e', b'f', b'r', b'e', b'\x84', b'\x00', b'\x01', b'\x03', b'\x00', b'\x00', b'\x0b', b'\x04', b'\xd8', b'\xff']

I cannot seem to find a good way to split these and I need to split them to send them to a microcontroller as an array of individual bytes.

Ruben
  • 187
  • 1
  • 7

1 Answers1

1

If you don't have a lot of data, the quick and dirty way would work

current_list = [b'\xd3\xb6\x00\x00', b'\x80\x82efre\x84\x00', b'\x01', b'\x03', b'\x00\x00', b'\x0b\x04', b'\xd8\xff']
new_list = []
for elem in current_list:
    for byte in elem: 
        new_list.append(byte)
Vvamp
  • 414
  • 4
  • 12
  • 1
    Yeah I was thinking the same but for some weird reason that returns a list of integers. using byte_to_bytes(1,'little') seems to resolve that though – Ruben Jun 09 '22 at 14:31