gpt4 book ai didi

python - 如何在 python 3 中将二进制数据写入标准输出?

转载 作者:IT老高 更新时间:2023-10-28 21:12:05 25 4
gpt4 key购买 nike

在 python 2.x 中我可以这样做:

import sys, array
a = array.array('B', range(100))
a.tofile(sys.stdout)

然而,现在我得到一个 TypeError: can't write bytes to text stream。我应该使用一些 secret 编码吗?

最佳答案

更好的方法:

import sys
sys.stdout.buffer.write(b"some binary data")

关于python - 如何在 python 3 中将二进制数据写入标准输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/908331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com