3

What does "%ds" in following codes mean?

theline = 'aaaaaeeebbbbbbbbccccccccddd'
baseformat = "5s 3x 8s 8s"
numremain = len(theline) - struct.calcsize(baseformat)
format = "%s %ds" % (baseformat, numremain)
s1, s2, s3, s4= struct.unpack(format, theline)
Lancert9
  • 41
  • 1
  • 5

2 Answers2

7

The '%ds' is not a format specifier. It's '%d' followed by 's':

>>> "%ds" % 6
6s
dlask
  • 8,776
  • 1
  • 26
  • 30
1

"%ds" here is a format specifier plus a single string "s". For the codes above, it specifies the length of "remain string".

Lancert9
  • 41
  • 1
  • 5