python - 如何将内存 View 转换为字节?

标签 python python-3.x

如何将 Python 内存 View 转换为字节?

例如:

>>> convert(memoryview(b"test"))
b"test"

最佳答案

Python 的内存 View 有一个 tobytes()允许您这样做的方法。您还可以对该对象调用 bytes()

请记住,将 memoryview 对象转换为字节会复制数据,并且您可以在大多数地方以任何一种方式使用 memoryview。我不建议你转换。

关于python - 如何将内存 View 转换为字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53229236/

相关文章:

python - 为什么 numpy.spacing(0) 给我一个不可能的数字?

python - 使用 Luhn 算法验证信用卡号 Python

python - 如何在Python中列出远程Windows主机共享目录?

python - Python的 "=="到底是做什么的

python - 如何同时使用 Anaconda 版本(2.7 和 3.5)?

python-3.x - 使用 Telegram API 阅读公共(public) channel 文本

python - 使用索引作为 x 轴标签绘制直方图

python - 索引错误: list index out of range for making a variable structure library

python-3.x - 类型错误 : Improper input: N=2 must not exceed M=1

python-3.x - 通过最接近的匹配合并不同长度的两列上的两个 Dataframe