binary conversion issues

godavemon davefowler at gmail.com
Tue Aug 8 15:59:58 EDT 2006


You guys are awesome!  I had to set the 'b' flag when writing the
binaries.

file_obj = open('filename.bin', 'wb')

instead of just using 'w'

It worked fine for all of the other 10 binary files I made, but had a
small error with one of them.  In that one file's case it wrote out an
extra 4 bytes in the middle somewhere.  Strange.

Thanx for your help.


Grant Edwards wrote:
> On 2006-08-08, godavemon <davefowler at gmail.com> wrote:
>
> > I'm using python's struct and binascii modules to write some values
> > from my parser to binary floats.  This works great for all of my binary
> > files except one.  For some reason this file is saving to 836 (stated
> > by my command shell) bytes instead of 832 like it should.
>
> I'm just making a wild-ass guess since you didn't provide any
> sample code or data, but it sounds like cr/lf translation
> problem to me.  Make sure you open the files in binary mode
> using the "b" flag.
>
> --
> Grant Edwards                   grante             Yow!  Is this "BIKINI
>                                   at               BEACH"?
>                                visi.com




More information about the Python-list mailing list