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
write to stdout in binary mode - is it possible? #48821
Comments
I have a program that needs to output binary data to stdout. for example something like When I try this, I get an error like: I know I can open a file in 'wb' mode and write to it, but what |
You can write to the underlying raw stream: sys.stdout.buffer.write(b'abc') |
Is that an official way? If yes, it needs to be documented. |
Documented in r67365. |
I don't consider sys.stdout.buffer.write(b'abc') There needs to be a standard, portable, documented way to put stdout I don't have a problem changing open statements to support binary |
switch to binary mode
>>> sys.stdout = sys.stdout.buffer
switch back
>>> sys.stdout = sys.__stdout__ |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: