Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98764 > unrolled thread
| Started by | kent nyberg <kent@z-sverige.nu> |
|---|---|
| First post | 2015-11-13 15:15 -0500 |
| Last post | 2015-11-13 15:15 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Problems using struct pack/unpack in files, and reading them. kent nyberg <kent@z-sverige.nu> - 2015-11-13 15:15 -0500
| From | kent nyberg <kent@z-sverige.nu> |
|---|---|
| Date | 2015-11-13 15:15 -0500 |
| Subject | Re: Problems using struct pack/unpack in files, and reading them. |
| Message-ID | <mailman.303.1447445714.16136.python-list@python.org> |
On Fri, Nov 13, 2015 at 12:36:22PM -0700, Ian Kelly wrote:
> On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg <kent@z-sverige.nu> wrote:
> > def LoadCommandAndReact(place_to_read):
> > global RegisterAX
> >
> > tmp = place_to_read.read()[RegisterAX:calcsize('HH')]
>
> It looks like you're trying to get a slice of length 4 here, starting
> at the value of RegisterAX. What you're actually getting is a slice
> starting at the value of RegisterAX and ending at 4. You probably want
> this instead:
>
> tmp = place_to_read.read()[RegisterAX:RegisterAX + calcsize('HH')]
> --
> https://mail.python.org/mailman/listinfo/python-list
Even with that, it still gets wrong.
I also tried .read()[RegisterAX:RegisterAX+4]
As for the other suggestions you had in the second reply, I can comment on them later.
For now though, I just want to be able to loop this specific function.
I do appriciate that you took the time. :)
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.
I have even tried doing .read(4), since then python should manage where to start and read 4?
Still it complains?
Back to top | Article view | comp.lang.python
csiph-web