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


Groups > comp.lang.python > #98759 > unrolled thread

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

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2015-11-13 12:45 -0700
Last post2015-11-13 12:45 -0700
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.


Contents

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

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

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-11-13 12:45 -0700
SubjectRe: Problems using struct pack/unpack in files, and reading them.
Message-ID<mailman.299.1447443985.16136.python-list@python.org>
As long as I'm replying to this, I see a few more issues to comment on:

On Fri, Nov 13, 2015 at 12:20 PM, kent nyberg <kent@z-sverige.nu> wrote:
>     if place_to_read.closed:
>        print("Drive error. Drive closed.")

You probably also want to break or return here. Even better: raise an
exception instead of printing.

That said, why would this ever be closed here, since you just read
from it two lines prior (which would have raised an exception if the
file were closed), and you haven't closed it in the meantime?

>     if checkfirstbit(klar[RegisterAX]):
>        print("First bit is set. Move Cmd.")
>        if (klar[0] & 0b0111111111111111):
>           print("Cmd ERROR: Multiple commands is set.")

Why do you pass the commands in a bit field if you're not going to
allow multiple commands to be set? Also, see above about
break/return/exception.

>           pass

Unnecessary.

>     #Change RegisterAX offset+2bytes,
>     RegisterAX=+2   #We read two bytes per cycle. Becaus command is first, and variables are second.

This sets RegisterAX to 2. Specifically, positive 2. If you want to
*add* 2, you probably meant to write:

    RegisterAX += 2

This also points out a good reason for using spaces around operators,
as "RegisterAX =+ 2" would have caused a SyntaxError and been more
easily detectable.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web