Re: Style help for a Smalltalk-hack

Discussion in 'Python' started by Dennis Lee Bieber, Oct 23, 2012.

  1. On Mon, 22 Oct 2012 17:43:00 -0700, Travis Griggs
    <> 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
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Oct 23, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Travis Griggs

    Style help for a Smalltalk-hack

    Travis Griggs, Oct 23, 2012, in forum: Python
    Replies:
    0
    Views:
    132
    Travis Griggs
    Oct 23, 2012
  2. MRAB
    Replies:
    0
    Views:
    124
  3. Travis Griggs

    Re: Style help for a Smalltalk-hack

    Travis Griggs, Oct 23, 2012, in forum: Python
    Replies:
    0
    Views:
    152
    Travis Griggs
    Oct 23, 2012
  4. Travis Griggs

    Re: Style help for a Smalltalk-hack

    Travis Griggs, Oct 23, 2012, in forum: Python
    Replies:
    0
    Views:
    156
    Travis Griggs
    Oct 23, 2012
  5. Ian Kelly

    Re: Style help for a Smalltalk-hack

    Ian Kelly, Oct 23, 2012, in forum: Python
    Replies:
    0
    Views:
    163
    Ian Kelly
    Oct 23, 2012
Loading...

Share This Page