用于实现二进制文件格式的Python模块?
我经常发现自己需要编写代码来与没有现有工具的二进制文件格式进行交互。我正在寻找一种简单的方法来实现结构化二进制格式的读取器/写入器——理想情况下,它可以让我使用某种简单的声明性格式创建读取器。
我找到了 Construct 模块,它可以工作,但似乎已被作者放弃。我想知道人们是否已经使用过任何替代方案。
I frequently find myself needing to write code to interact with binary file formats for which there aren't existing tools. I'm looking for an easy way to implement readers/writers for structured binary formats -- ideally something that will let me create the reader using some sort of simple declarative format.
I've found the Construct module, which works but seems to have been largely abandoned by the author. I'm wondering if there are any alternatives out there that people have worked with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我会使用 bitstring 模块,但我在编写它时可能会有偏见。作为示例,手册中有一些用于读取/写入二进制格式的简单代码。
这是通过二进制格式创建的一种方法:
以及随后解析它的一种方法:
Personally I'd use the bitstring module, but I may be biased as I wrote it. There's some simple code for reading/writing a binary format in the manual as an example.
This is one way to create via a binary format:
and one method to parse it afterwards:
看看Hachoir。
Have a look at Hachoir.