I have a list of hex strings representing bytes, of the form \"FF\". I want to convert the whole list to a byte stream so I can send it over a socket (Python 3). It looks
hexstrings = ["DE", "AD", "BE", "EF"] # big-endian 0xDEADBEEF bytes = bytearray(int(x, 16) for x in hexstrings) bytes = bytearray.fromhex("".join(hexstrings)) # Python 2.6 may need u""
If you've got a lot of 'em, it might be worthwhile to see which of those is fastest.