这是一个结构非常简单的二进制文件,用于学习。每个寄存器有3个数字:32位浮点、64位浮点和另一个32位浮点。如果我以十六进制将其转储到屏幕上,则如下所示:
0000000: 0800 0000 0000 0000 0000 0000 0800 0000 ................
0000010: 0800 0000 0000 0000 0000 f03f 0800 0000 ...........?....
0000020: 0800 0000 182d 4454 fb21 0940 0800 0000 .....-DT.!.@....
(…)
如果我手动复制二进制格式的第三行,我可以将其读入三个变量:
^{pr2}$这是可行的,但我需要从磁盘读取文件,不仅要手动以二进制形式复制每个寄存器,因为我需要使用数百万个数据来执行此操作。我需要与ascii文件中使用的以下命令等效的命令:
l1, value, l2 = pylab.loadtxt('./test_file.binary',unpack=True)
这在这里行不通。在
以二进制模式读取文件:
这是发电机。要消耗它:
^{pr2}$你可以试试这个方法
相关问题 更多 >
编程相关推荐