在Python中读取大型二进制文件的部分内容

时间:2017-03-08 13:33:48

标签: python binaryfiles large-data

我想用Python中的大型二进制数据文件中的随机块读取,到目前为止,我还没有找到解决问题的好方法。

到目前为止我所拥有的是以下内容,但它只能在第一个 n 整数中读取,并且无法在文件中的其他位置启动。

j

此外,文件太大而无法使用

import numpy as np  
#Pick an n here.

f = open("test2.rd14")
a = np.fromfile(f, dtype = np.uint16, count=int(n))

1 个答案:

答案 0 :(得分:3)

一切都在文档中。

https://docs.python.org/3.6/tutorial/inputoutput.html

以二进制模式打开

f = open("test2.rd14", "rb")

然后你想使用搜索方法,

f.seek(byte_n)

从别处开始。