1

我正在以这种方式读取 python 2.7.3 中的二进制文件:

import os, struct
from numpy import *

win_span = 8
coinc_window = zeros(2)
event = asarray((False, False, False, False))
Statistics = zeros(5)

with open("myfile", "rb") as f:
    byte = f.read(8)
    while byte != "":
        time_bin = struct.unpack("<Q", byte)[0]
        byte = f.read(2)
        channel_tag = struct.unpack("<H", byte)[0]
        if time_bin > coinc_window[1] + win_span:
            Statistics[4] += event[0]*event[2]
            event = asarray((False, False, False, False))
            coinc_window = coinc_window[::-1]
            coinc_window[1] = time_bin
        event[channel_tag-1] = True
        Statistics[channel_tag-1] += 1
        byte = f.read(8)    
print "Fin"

它适用于小型二进制文件(~2MB),但是当我为大小超过~6MB的二进制文件运行它时,它实际上完成了运行,但也给出了这个错误:“分段错误”。我不知道它出了什么问题?

4

0 回答 0