I was reading though a library of python code, and I’m stumped by this statement:
struct.pack( "<ii%ds"%len(value), ParameterTypes.String, len(value), value.encode("UTF8") )
I understand everything but%d, and I’m not sure why the length of value is being packed in twice.
As I understand it, the structure will have little endian encoding (<) and will contain two integers (ii) followed by %d, followed by a string (s).
What is the significance of %d?
It is an ordinary string format which is being used to create the struct format
Try reading it to begin with as an ordinary string (forget
structfor the moment) …If, for example, the length of the value iterable is 4 then the string will be,
<ii4s. This is then passed tostruct.packready to pack two integers followed by a string of length four bytes from thevalueiterable