0

A data file binaryFile.bin was written as so in MATLAB:

stream = fopen (dst_file.c_str(),"wb");
fwrite(data,sizeof(float),4*num,stream);
fclose(stream);

I would like to retrieve this in Python. What I have tried thus far is:

fileName = '~/binaryFile.bin'
with open(fileName, mode='rb') as file: 
fileContent = file.read()

This gives me fileContent, which is a python string. (For example, the first couple samples look something like this: "94QB\\x9a\\x99\\xe9@)\\").

I simply want to read back the entire fileContent as the original array of floats. How do I do that? Thanks.

7
  • How many bytes are in the file (len(fileContent))? Is that the whole file you gave us? 19 bytes does not really fit any known float format. Commented Apr 30, 2017 at 18:36
  • @MartijnPieters As I said in the question, the first couple samples is that string. len(fileContent) gives 1919632 Commented Apr 30, 2017 at 18:38
  • use the array module. Commented Apr 30, 2017 at 19:08
  • @juanpa.arrivillaga Thanks, may you please give a usage example for this case? Cheers. Commented Apr 30, 2017 at 19:11
  • stackoverflow.com/questions/33319727/… Commented Apr 30, 2017 at 21:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.