Python字节缓冲区对象?
发布时间:2020-10-19 06:10:15 所属栏目:Python 来源:互联网
导读:在 Python中有一个字节缓冲区对象,我可以附加特定类型的值吗? (优选具有可指定的端性) 例如: buf.add_int(4) # should add a 4 byte integerbuf.add_short(10) # should add a 2 byte shortbuf.add_byte(24) # should add a byte 我知道我可以使用struct.pa
在 Python中有一个字节缓冲区对象,我可以附加特定类型的值吗? (优选具有可指定的端性) 例如: buf.add_int(4) # should add a 4 byte integer buf.add_short(10) # should add a 2 byte short buf.add_byte(24) # should add a byte 我知道我可以使用struct.pack,但这种方法看起来更容易.理想情况下,它应该像Java中的DataOutputStream和DataInputStream对象一样完成任务. 解决方法你可以随时使用 bitstring.它能够做所有你要求的事情和更多.>>> import bitstring >>> stream=bitstring.BitStream() >>> stream.append("int:32=4") >>> stream.append("int:16=10") >>> stream.append("int:8=24") >>> stream BitStream('0x00000004000a18') >>> stream.bytes 'x00x00x00x04x00nx18' 这是documentation的链接. (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – 改变seaborn heatmap颜色条上的刻度尺寸
- 如何在Python中获取logging.FileHandler的文件名?
- python – Django交叉表模型结构
- python – pip install hyperopt和hyperas失败
- 如何在多个核心上运行Keras?
- python – Django Crispy Forms添加Div提交按钮
- python – hashlib.md5()TypeError:Unicode对象必须在散列
- python – Pandas:根据来自另一列的匹配替换列值
- python – Mac OS上“import cv”期间的“分段错误”
- python中is和==的区别