[New-bugs-announce] [issue4571] write to stdout in binary mode - is it possible?

jeff deifik report at bugs.python.org
Sun Dec 7 03:40:10 CET 2008


New submission from jeff deifik <jeff at jeffunit.com>:

I have a program that needs to output binary data to stdout.
I don't want to convert it to a string.

for example something like
sys.stdout.write('0o377')
to write a byte with all the bits turned on.

When I try this, I get an error like:
    sys.stdout.write(data)
  File "/usr/local/lib/python3.0/io.py", line 1484, in write
    s.__class__.__name__)
TypeError: can't write bytes to text stream

I know I can open a file in 'wb' mode and write to it, but what
I want to do is somehow switch the mode of stdout to 'wb' mode.
I read lots of python 3 documentation, as well as searched without
finding a way.

----------
components: Interpreter Core
messages: 77208
nosy: lopgok
severity: normal
status: open
title: write to stdout in binary mode - is it possible?
type: crash
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4571>
_______________________________________


More information about the New-bugs-announce mailing list