Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.stdout Python2.x VS Python 3.x #4

Open
limboinf opened this issue Jan 14, 2016 · 0 comments
Open

sys.stdout Python2.x VS Python 3.x #4

limboinf opened this issue Jan 14, 2016 · 0 comments

Comments

@limboinf
Copy link
Owner

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant