Reputation: 10429
I read the first few bytes of a JPEG
f = open(filename, 'rb')
firstTwoBytes = f.read(2)
if firstTwoBytes != '\xff\xd8':
firstTwoBytes iny my debugger is: bytes: b'\xff\xd8' which is correct?
So my String comparison fails. How best to fix this?
Thanks
Upvotes: 0
Views: 249
Reputation: 11315
So, compare to binary not to the string:
f = open(filename, 'rb')
firstTwoBytes = f.read(2)
if firstTwoBytes != b'\xff\xd8':
Upvotes: 1