I'm trying to print a list of bytes to a file in hex (or decimal, doesn't really make a difference for the sake of the question I believe). I'm baffled by how hard this appears to be in Python?
Based on what I found here (and on other SO questions), I already managed to do this:
>>> b
[12345, 6789, 7643, 1, 2]
>>> ' '.join(format(v, '02x') for v in b)
'3039 1a85 1ddb 01 02'
Now... this is already a good start, but... for larger numbers the individual bytes are grouped and attached to each other. This should not happen. There should be a space between them, just like is the case with the two last numbers.
Of course, I could just do some string manipulation afterwards and insert some spaces, but... that sounds like a very hacky way, and I refuse to believe there isn't a cleaner way to do this.
So, what I want is this:
'30 39 1a 85 1d db 00 01 00 02'
How can I do this?