Error in using `struct.pack` for writing data to file

前端 未结 1 642
星月不相逢
星月不相逢 2021-01-14 05:22

I have a numpy.ndarray sample of numbers, each between 1 and 2**20.

I\'d like to write it into a binary file, such that each element is rep

相关标签:
1条回答
  • 2021-01-14 05:36

    Open the file in binary mode:

    outputFile = open('testDS', 'wb')
    

    Otherwise, the file object may do some magic translation of newline characters that show up in your binary data, resulting in additional characters being written to the file. See, for example, https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

    0 讨论(0)
提交回复
热议问题