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


Groups > comp.lang.python > #77432

Re: ANN: binario - simple work with binary files

Newsgroups comp.lang.python
Date 2014-09-01 21:35 -0700
References <33f920ca-16ce-40ce-ab3a-4479beeeae4e@googlegroups.com> <23onv9dom4ek64m273bfic5n0c2ldnij8b@4ax.com> <68d1665b-5369-43f0-8177-352b8949ab20@googlegroups.com> <h34a0aphuq9tjm5548h2t0c4127a2sjg8o@4ax.com>
Message-ID <85e4a393-c926-44cd-a0dd-1654cfaa6b4d@googlegroups.com> (permalink)
Subject Re: ANN: binario - simple work with binary files
From Rustom Mody <rustompmody@gmail.com>

Show all headers | View raw


On Tuesday, September 2, 2014 6:05:19 AM UTC+5:30, Tim Roberts wrote:
> Rustom Mody wrote:

> >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote:

> >> To the equivalent code with struct:
> >>   import struct
> >>   dscrp = "H?fs5B"
> >>   f = open('file.dat')
> >>   stuff = struct.unpack( dscrp, f.read() )
> >>   print stuff
> >> In both cases, you have to KNOW the format of the data beforehand.  If you
> >> do a read_short where you happen to have written a float, disaster ensues.
> >> I don't really see that you've added very much.
> >I thought much the same.
> >However notice your f.read(). Its type is string.
> >What if file.dat is a 1GB wav file?

>   f.seek(512000)
>   stuff = struct.unpack( dscrp, f.read(128) )

And what if the struct you are (trying to) unpack is greater or less
than 128 bytes?

> The point is that files already know how to position themselves.

Sure.
But its not enough. One can write a generator that yields one char
at a time.  How to feed that to struct.unpack??

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


Thread

ANN: binario - simple work with binary files bwatas@gmail.com - 2014-08-23 09:24 -0700
  Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-08-23 20:13 -0700
  Re: ANN: binario - simple work with binary files Алексей Саскевич <bwatas@gmail.com> - 2014-08-25 02:58 -0700
    Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-08-25 05:33 -0700
    Re: ANN: binario - simple work with binary files Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-25 14:20 +0100
  Re: ANN: binario - simple work with binary files Tim Roberts <timr@probo.com> - 2014-08-25 18:28 -0700
    Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-08-25 20:45 -0700
      Re: ANN: binario - simple work with binary files Tim Roberts <timr@probo.com> - 2014-09-01 17:35 -0700
        Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-09-01 21:35 -0700
          Re: ANN: binario - simple work with binary files Tim Roberts <timr@probo.com> - 2014-09-06 11:34 -0700

csiph-web