pytool icon indicating copy to clipboard operation
pytool copied to clipboard

sys.stdout Python2.x VS Python 3.x

Open limboinf opened this issue 9 years ago • 0 comments

将字节数据直接写入文件的缓冲区

In python2.x:

>>>import sys
>>>sys.stdout.write(b"hello")
hello

In python3.x:

>>> import sys
>>> sys.stdout.write(b'Hello\n')
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
TypeError: must be str, not bytes
>>> sys.stdout.buffer.write(b'Hello\n')
Hello
5

Python2.x 没有sys.stdout.buffer

limboinf avatar Jan 14 '16 01:01 limboinf