2017-03-08 69 views
1

我想從Python中的大型二進制數據文件中隨機讀取塊,至今我還沒有找到解決我的問題的好方法。在Python中閱讀大型二進制文件的部分

我到目前爲止是以下內容,但它只能讀取第一個n整數,並且無法在文件的其他位置啓動。

import numpy as np 
#Pick an n here. 

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

此外,在過大的文件,使用

with open("test2.rd14") as file: 
filecontent = file.read() 
+0

你應該檢查[this](http://stackoverflow.com/questions/1035340/reading-binary-file-in-python-and-looping-over-each-byte)它可能有幫助。 – kessi

回答