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


Groups > comp.lang.python > #31914

Re: Style help for a Smalltalk-hack

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Style help for a Smalltalk-hack
Date 2012-10-22 21:48 -0400
Organization > Bestiaria Support Staff <
References <168DF25C-0C43-45F2-BEDC-17AC4210F207@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2647.1350956931.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, 22 Oct 2012 17:43:00 -0700, Travis Griggs
<travisgriggs@gmail.com> declaimed the following in
gmane.comp.python.general:

> I'm writing some code that does a structured read from formatted binary file. The code I came up with looks like:
> 
> # get the first four bytes, the first gap field
> chunk = byteStream.read(4)
> while chunk:
>     # interpret the gap bytes
	<snip> 
> I can't help but thinking that there's some better way (i.e. more pythonic) to do this that doesn't involve having to use another module (Construct) or exploring generators or something like that. What bugs me about it is that there is two different styles for reading/decoding values from the byte stream. valveCount and signatures are both paired invocations of unpack() and read(). But to detect the end of the stream (file), I have to split the read() and unpack() of the gap value across 3 different lines of the code, and they don't even sit adjacent to each other.
> 

	Is there any chance this file might fit an IFF spec? If it does, see
the "chunk" module (Python 2.7.2 library reference section 21.6)

	At the least, even if it doesn't fit the full IFF spec (no chunk
name, perhaps) you might be able to purloin the source code to create
your own comparable module.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

Re: Style help for a Smalltalk-hack Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-22 21:48 -0400

csiph-web