I have the following list of bytes:
[b'S', b'\x00', b't', b'\x00', b'a', b'\x00', b'n', b'\x00', b'd', b'\x00', b'a', b'\x00', b'r', b'\x00', b'd', b'\x00', b'F', b'\x00', b'i', b'\x00', b'r', b'\x00', b'm', b'\x00', b'a', b'\x00', b't', b'\x00', b'a', b'\x00', b'.', b'\x00', b'i', b'\x00', b'n', b'\x00', b'o', b'\x00', b'y', b'\x02', b'\x03', b'S', b'\x00', b't', b'\x00', b'a', b'\x00', b'n', b'\x00', b'd', b'\x00', b'a', b'\x00', b'r', b'\x00', b'd', b'\x00', b'F', b'\x00', b'i', b'\x00', b'r', b'\x00', b'm', b'\x00', b'a', b'\x00', b't', b'\x00', b'a', b'\x00', b'.', b'\x00', b'i', b'\x00', b'n', b'\x00', b'o', b'\x00', b'y', b'\x02', b'\x03', b'S', b'\x00', b't', b'\x00', b'a', b'\x00', b'n', b'\x00', b'd', b'\x00', b'a', b'\x00', b'r', b'\x00', b'd', b'\x00', b'F', b'\x00', b'i', b'\x00', b'r', b'\x00', b'm', b'\x00', b'a', b'\x00', b't', b'\x00', b'a', b'\x00', b'.', b'\x00', b'i', b'\x00', b'n', b'\x00', b'o', b'\x00', b'y', b'\x02', b'\x03', b'S', b'\x00', b't', b'\x00', b'a', b'\x00', b'n', b'\x00', b'd', b'\x00', b'a', b'\x00', b'r',
Is there a simple way for me to convert that into one long byte
? I guess techincally called a bytestring
(though I am not sure about that).
Note, I looked here but it does not work for me. Also, is the correct term for one long byte
object (such as b'\f\x04\55'
) a byte object
or something else?
Use bytes.join
:
>>> b = [b'S', b'\x00', b't', b'\x00', b'a']
>>> b''.join(b) # b'': separator
b'S\x00t\x00a'
bytes
and bytearray
objects have the join
method:
In [37]: b''.join([b'S', b'\x00', b't', b'\x00', b'a', b'\x00', b'n', b'\x00', b'd', b'\x00'])
Out[37]: b'S\x00t\x00a\x00n\x00d\x00'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With