Python 3:获取与Python 2 struct.pack输出匹配的struct.pack输出

杜海姆

在Python 2中:

import struct
struct.pack('B', 21)[0] # returns '\x15'

在Python 3中:

import struct
struct.pack('B', 21)[0] # returns 21

有什么方法可以在Python 3中创建Python 2返回的字节字符串?任何指针将不胜感激!

奥尔普

只是不要索引返回的字节字符串:

>>> struct.pack('B', 21)
b'\x15'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在python中使用struct pack

相当于Python的struct.pack / struct.unpack的Golang

等价于Python的C#中的“ struct.pack / unpack”吗?

尝试保存字节序时,Python struct.pack()'struct.error:struct格式的错误字符'

编写与Python版本无关的代码:struct.pack

python struct.pack():将多个数据打包到列表或元组中

python struct.pack和vs vs matlab fwrite

struct pack返回太长

了解python 2.7和3.5+中的struct.pack

即使删除对象后,Python struct.pack也会导致内存泄漏

从Python 2到Python 3 Struct Pack的问题

msgpack可以提供更好的性能和python的struct.pack()相同的功能吗?

Arduino和Python(3.x)之间的Serial.read()和Struct.pack /串行通信问题

用cython比struct.pack更快

Python struct.pack和解压缩

struct.pack的结果很奇怪?

struct.pack()Python未知字段的长度,通过套接字发送

Python 3 struct.pack()打印奇怪的字符

将python转换为java:struct.pack('h',int)

做Python的C ++代码struct.pack('> I',val)

struct.unpack和struct.pack如何工作?

python-bytes()vs struct.pack()

使用带有负数的struct.pack

此python代码的含义是什么:<L在struct.pack(“ <L”,self.src)中

Python:Struct.pack(format,[...]),打包数据的大小不同,尽管格式几乎相同

python:struct pack的大小比预期的长-为什么会发生这种情况?

C 相当于 Python 的 struct.pack 吗?

无法在python中struct.pack连接名称

Kotlin:编码和解码二进制结构数据(Kotlin 等效于 Python 的 struct.pack 和 struct.unpack)