This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Manux
Recipients Manux
Date 2009-09-16.21:53:17
SpamBayes Score 4.10999e-12
Marked as misclassified No
Message-id <1253138000.08.0.430539071948.issue6924@psf.upfronthosting.co.za>
In-reply-to
Content
Using the following command in Python 2.6.1:

>>> struct.unpack("BI","12345")
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    struct.unpack("BI","12345")
error: unpack requires a string argument of length 8

I get this error message. What confused me was that doing
>>> struct.unpack("IB","12345")
(875770417, 53)
Worked just fine.

I have found out that this only happens using the native byte
order("@"), which is the default.
For Example:
>>> struct.unpack("!BI","12345")
(49, 842216501)
Works, and all other variants, =, <, > (native standard,little endian,
and small endian) also do.

I haven't found anything about that in the documentation.

Also, the requested 3 other bytes arent event used:
>>> struct.unpack("I","abcd")
(1684234849,) # see the big number starting with 16
>>> ord("x")
120
>>> struct.unpack("BI","xabcd") # we get the error
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    struct.unpack("BI","xabcd")
error: unpack requires a string argument of length 8
>>> struct.unpack("BI","xabcdefg")
(120, 1734763876) # not the same here
>>> struct.unpack("BI","xabcabcd")
(120, 1684234849) # same here
>>> struct.unpack("BI","x___abcd")
(120, 1684234849) # same again
History
Date User Action Args
2009-09-16 21:53:20Manuxsetrecipients: + Manux
2009-09-16 21:53:20Manuxsetmessageid: <1253138000.08.0.430539071948.issue6924@psf.upfronthosting.co.za>
2009-09-16 21:53:18Manuxlinkissue6924 messages
2009-09-16 21:53:17Manuxcreate