0
test = struct.unpack('>%dH' % 1, '\x00\x44') 

Is confusing me. I thought it means take the first 8 bytes and treat them as a double then take the next two and treat them as a short, and do all of that one time. But it means something else and I can't figure out what. It seems to realize that there is no double present and converts those two bytes to one number.

This code

test = struct.unpack('>1dH' , '\x00\x44')

Throws an error because it's expecting to find a double...

Can anyone tell me what the difference between these two are?

Thanks

1 Answer 1

3

'>%dH' % 1 is equivalent to '>1H'.

>>> '>%dH' % 1
'>1H'

'>%dH' % 1 is using old-style string formatting to replace the %d with 1.

So the struct format is specifying a big-endian two-byte unsigned short.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.