python 结构体解包 [英] python struct unpack

查看:53
本文介绍了python 结构体解包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试转换以下 perl 代码:

I'm trying to convert the following perl code:

unpack(.., "Z*")

到 python,但是 struct.unpack() 中缺少*"格式修饰符似乎使这成为不可能.有没有办法在python中做到这一点?

to python, however the lack of a "*" format modifier in struct.unpack() seems to make this impossible. Is there a way I can do this in python?

附言perldoc 中 perl 中的*"修饰符 - 为重复计数提供 * 而不是数字意味着使用多少项,...

P.S. The "*" modifier in perl from the perldoc - Supplying a * for the repeat count instead of a number means to use however many items are left, ...

所以虽然python像perl一样有数字重复计数,但似乎缺少*重复计数.

So although python has a numeric repeat count like perl, it seems to lack a * repeat count.

推荐答案

python 的 struct.unpack 没有 Z 格式

python's struct.unpack doesn't have the Z format

Z  A null-terminated (ASCIZ) string, will be null padded.

我觉得

unpack(.., "Z*")

应该是:

data.split('\x00')

虽然这去除了空值

这篇关于python 结构体解包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆