Open numpy-gitbot opened 12 years ago
Attachment added by trac user allenatmention:transpireinc.com on 2012-09-04: example.py
trac user allenatmention:transpireinc.com wrote on 2012-09-05
Note: After reading some of the Python3 documentation, I discovered that setting the buffering
to 0 in the open()
statement allows my test program to run correctly.
Original ticket http://projects.scipy.org/numpy/ticket/2210 on 2012-09-04 by trac user allen@transpireinc.com, assigned to unknown.
I have a binary file which is written by a C program. It is essentially a bunch of integer and single precision floating point values written one after another. I'm trying to read the file partly with the python
read()
function (usually followed bystruct.unpack()
) and partly withnumpy.fromfile()
. Generally, I'm extracting the scalars withread()/unpack()
and the arrays withfromfile()
. I've discovered thatfromfile()
can become confused if the file itself is larger than a particular size. On my Red Hat Enterprise Linux 6.3 and Ubuntu 12.04 64-bit systems, this size is 4096 bytes. It appears to work OK on windows xp regardless of the file size.I attached a simple program which writes a simple binary file and then reads it back. It should produce the output:
On linux I get:
You see that the first array is read OK, but the file
offset1
following thefromfile()
call is incorrect. It should be 241, but is 242 instead.I glanced at the C code which implements
fromfile()
but I didn't see anything obviously incorrect. Except, it does make a copy of the underlying file handle to do thefromfile()
. I wondered if this was exposing a bug in GLIBC or the python file handling layer.Thanks, Allen