I am receiving the error above where it asking me for a string length of 4 as I am trying to unpack a float from a binary file. My code runs perfectly fine on my Mac, however it falls short on Windows. The code is as follows:
for i in range (0,elec_array.nb_chan):
elec_array.chan[i].x = struct.unpack('f',f.read(4))[0]
elec_array.chan[i].y = struct.unpack('f',f.read(4))[0]
The problem occurs at elec_array.chan[i].x line. It does not occur immediately however, it will go through a few iterations in the loop first, and then finally give the error that a string of length 4 is required. Again, the code works perfectly fine on Mac, but for some reason stops working on my Windows 7 PC. Any help would be appreciated!
You probably forgot to open the file in binary mode. In text mode, a
0x0d0x0asequence gets shortened to0x0aand your file will be the wrong size.