[docs] array: magical number -0.0050385478258801655 --> ValueError: string length not a multiple of item size

Pete googligerpete at gmail.com
Fri Mar 21 12:26:16 CET 2014


Dear all,

Inspired by [0] I tried to write a binary file with the help of
array.tofile()
I wonder why my code is not working at re-importing the binary file,
handling a specific float:

<code>
from array import array

output_file = open('bug', 'wb')
float_array = array('d', [-0.0050385478258801655])#is not working
#float_array = array('d', [-0.0050385478258])#works
#float_array = array('d', [-0.012345678912345])#works, too
float_array.tofile(output_file)
output_file.close()


input_file = open('bug', 'r')
float_array = array('d')
float_array.fromstring(input_file.read())
input_file.close()
print float_array
</code>

The error is:
"ValueError: string length not a multiple of item size"

(Running Python(x,y) 2.7.2.1 on a Win7 64bit, code is executed within scite
IDE)

Best Regards,
Peter



[0]:
http://stackoverflow.com/questions/807863/how-to-output-list-of-floats-to-a-binary-file-in-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20140321/404e09f9/attachment.html>


More information about the docs mailing list