Problems using struct pack/unpack in files, and reading them.

Ian Kelly ian.g.kelly at gmail.com
Fri Nov 13 16:05:04 EST 2015


On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg <kent at z-sverige.nu> wrote:
> What bothers me, is the error that says
> unpack requires a string argument of 4 bytes.
> Im thinking in the line of arguments? Does unpack look at the 4 bytes it has read, and tell for some
> reason say that unpacking needs an argument of 4 bytes?  I know that I can set the arguments
> for unpack. I have done that.  It is: unpack('>HH', tmp).
> So either '>HH' or tmp is wrong. Since '>HH' worked for the first run of the function, I assume its correct.
> And as far as I know,   doing .read()[RegisterAX:RegisterAX:+4]  should read the following
> 4 bytes.

By the way, I would strongly suggest that you print or log the value
of repr(tmp) so that you *know* what you're passing to unpack rather
than having to speculate about it.



More information about the Python-list mailing list