pytool
pytool copied to clipboard
sys.stdout Python2.x VS Python 3.x
将字节数据直接写入文件的缓冲区
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
。