r/Python • u/dasMoorhuhn • 13h ago
Discussion It seems like there was a change for how hex values and bytes can be compared
I made myself a lib for fast parsing RAW images from my sony camera.
My old code: ```python def check_for_endian(data:bytes) -> tuple[int, int]|None:
if data[:2] == 0x4949: # "II" LE
return 1, 0
if data[:2] == 0x4D4D: # "MM" BE
return 2, 0
return None
So it was possible to compare a hex value with bytes. Now it's not possible anymore, somehow, so I had to do this:
python
def check_for_endian(data:bytes) -> tuple[int, int]|None:
header_endian = struct.unpack_from("<h", data, 0)[0]
if header_endian == 0x4949: # "II" LE
return 1, 0
if header_endian == 0x4D4D: # "MM" BE
return 2, 0
return None
```
I'm a bit confused, have I used it wrong in the first place and I was never supposed to compare a hex value with bytes?
E: I use python 3.13.9 and uv 0.9.9