fromfile error on windows, not mac

jadamwil jadamwilson2 at gmail.com
Wed Jul 23 21:37:06 CEST 2008


I found the problem: I thought it was opening in binary mode on BOTH
windows and the mac, but on windows I passed "rb" with double quotes,
not 'rb' with single quotes to the open file function. Changing it to
'rb' fixed it.

On Jul 23, 8:25 am, Tommy Nordgren <tommy.nordg... at comhem.se> wrote:
> One question : Did you remember to open the file in binary mode?
> This MUST be done on windows.
> On 22 jul 2008, at 06.36, jadamwil wrote:
>
>
>
> > Hello,
> > I am using the numpy fromfile function to read binary data from a file
> > on disk. The problem is that the program runs fine on a Mac, but gives
> > an error or warning on windows when trying to read the data. I use it
> > like this:
>
> > Signal = zeros((N, 16), dtype=float32)
> > for sample in range(0, N):
> >  # this function gets the next position in the file to seek to
> >  s = getFilePos(sample)
>
> >  # go to the correct location in the file; this IS checked to make
> > sure it is within the file
> >  mFile.seek(s)
>
> >  # read the 16 float32 values from the file
> >  D = fromfile(mFile, dtype=numpy.float32, 16)
>
> >  # save D in Signal
> >  Signal[sample, :] = D
>
> > This will fail when sample is ~4. If I change the range to (5,N),
> > skipping the "bad" file location, it will run fine for a few samples,
> > and then give another error. The message it gives is:
> > "16 items requested but only 7 read"
>
> > So D is a 7x1 vector, and the program dies when it tries to assign D
> > to the slice of Signal ("ValueError: shape mismatch: objects cannot be
> > broadcast to a single shape").
>
> > On windows, the Python version is 2.5.2, and the most recent numpy and
> > scipy are being used as well. I tried using Enthought, but it gave
> > this error as well, in addition to a c runtime error whenever I
> > imported scipy (which is another post topic...).
>
> > Any ideas on what might be causing this? Is there a way to debug the
> > fromfile function? And, remember, this works perfectly on a Mac. Would
> > compiling everything (python, scipy, numpy) potentially solve this?
>
> > Thanks!
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> ----------------------------------
> Skinheads are so tired of immigration, that they are going to move to  
> a country that don't accept immigrants!
> Tommy Nordgren
> tommy.nordg... at comhem.se




More information about the Python-list mailing list