我处理的是一个字符分隔的十六进制文件,其中每个字段都有一个特定的开始代码。我以'rb'的格式打开了文件,但是我想知道,在我使用.find获取startcode的索引之后,如何从这个位置读取一定数量的字节?
这就是我加载文件的方式和我要做的
with open(someFile, 'rb') as fileData:
startIndex = fileData.find('(G')
data = fileData[startIndex:7]
其中7是要从find函数返回的索引中读取的字节数。我使用的是python2.7.3
Tags:
在python2.7下,可以获得bytestring中子字符串的位置,如下所示:
您可以查找特殊字符,为了与Python3k兼容,最好在字符前面加一个
^{pr2}$b
,表示这些是字节(在Python2.x中,它可以不使用):相关问题 更多 >
编程相关推荐