<div dir="ltr"><div><div><div><div>Dear all,<br><br></div>Inspired by [0] I tried to write a binary file with the help of array.tofile()<br></div>I wonder why my code is not working at re-importing the binary file, handling a specific float:<br>
<br></div><code><br>from array import array<br><br>output_file = open('bug', 'wb')<br>float_array = array('d', [-0.0050385478258801655])#is not working <br>#float_array = array('d', [-0.0050385478258])#works<br>
#float_array = array('d', [-0.012345678912345])#works, too<br>float_array.tofile(output_file)<br>output_file.close()<br><br><br>input_file = open('bug', 'r')<br>float_array = array('d')<br>
float_array.fromstring(input_file.read())<br>input_file.close()<br>print float_array<br></div></code><br><div><div><div><br></div><div>The error is:<br>"ValueError: string length not a multiple of item size"<br>
<br></div><div>(Running Python(x,y) 2.7.2.1 on a Win7 64bit, code is executed within scite IDE)<br><br></div><div>Best Regards,<br></div><div>Peter<br><br><br><br>[0]:<a href="http://stackoverflow.com/questions/807863/how-to-output-list-of-floats-to-a-binary-file-in-python">http://stackoverflow.com/questions/807863/how-to-output-list-of-floats-to-a-binary-file-in-python</a><br>
</div></div></div></div>