I have a large binary file of ieee 32bit floating point numbers.
In python I use:
f = file.read(4)
while f !='':
if len(f) == 4:
data =struct.unpack('>f', f)
print data
f = file.read(4)
to read it 4 bytes at a time
However, occasionally f would be size 1, and struct.unpack would complain that its input must be a string of size 4.
The filesize is divisible by 4, and this happens multiple times within the file.
What could be causing this?
Did you open the file in binary mode?
Anyway, a much better way to read your file is to use
array.fromfile()or NumPy.