的Python:搜索/读取二进制数据

编程入门 行业动态 更新时间:2024-10-25 02:22:41
本文介绍了的Python:搜索/读取二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我读在一个二进制文件(在这种情况下,一个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:搜索/读取二进制数据

本文发布于:2023-10-09 18:09:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476414.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:二进制数   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!