How to write binary data to stdout in python 3?

前端 未结 4 685
一个人的身影
一个人的身影 2020-11-29 22:26

In python 2.x I could do this:

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

Now however, I get a TypeErro

4条回答
  •  既然无缘
    2020-11-29 23:10

    import os
    os.write(1, a.tostring())
    

    or, os.write(sys.stdout.fileno(), …) if that's more readable than 1 for you.

提交回复
热议问题