Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98768

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

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Problems using struct pack/unpack in files, and reading them.
Date 2015-11-13 14:05 -0700
Message-ID <mailman.307.1447448752.16136.python-list@python.org> (permalink)
References <20151113192045.GA9913@z-sverige.nu> <CALwzidnL1N8efgJfM-EKTgqzmDjg2QwcZVVmDXJB2_QGyFnExA@mail.gmail.com> <20151113201510.GA10107@z-sverige.nu>

Show all headers | View raw


On Fri, Nov 13, 2015 at 1:15 PM, kent nyberg <kent@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 14:05 -0700

csiph-web