我读在一个二进制文件(在这种情况下,一个jpg),并需要找到在该文件中的一些的值。对于那些有兴趣,二进制文件是一个JPG,我试图通过寻找二元结构detailed这里。
I'm reading in a binary file (a jpg in this case), and need to find some values in that file. For those interested, the binary file is a jpg and I'm attempting to pick out its dimensions by looking for the binary structure as detailed here.
我需要找到FFC0二进制数据,直接跳到一定数量的字节,然后读取4个字节(这应该给我的图像尺寸)。
I need to find FFC0 in the binary data, skip ahead some number of bytes, and then read 4 bytes (this should give me the image dimensions).
什么是搜索二进制数据的价值的好办法?是否存在的查找等同或类似重?
What's a good way of searching for the value in the binary data? Is there an equivalent of 'find', or something like re?
推荐答案其实你可以将文件加载到一个字符串,并使用
You could actually load the file into a string and use
s.find('\xff\xc0')更多推荐
的Python:搜索/读取二进制数据
发布评论