好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

如何在python 3中将二进制数据写入stdout?

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

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

然而,现在我得到一个TypeError:无法将字节写入文本流.我应该使用一些秘密编码吗?

更好的方法:

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

查看更多关于如何在python 3中将二进制数据写入stdout?的详细内容...

  阅读:18次