Author lopgok
Recipients lopgok
Date 2008-12-07.02:40:08
SpamBayes Score 7.45952e-09
Marked as misclassified No
Message-id <1228617610.98.0.490718240035.issue4571@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-12-07 02:40:11lopgoksetrecipients: + lopgok
2008-12-07 02:40:10lopgoksetmessageid: <1228617610.98.0.490718240035.issue4571@psf.upfronthosting.co.za>
2008-12-07 02:40:09lopgoklinkissue4571 messages
2008-12-07 02:40:08lopgokcreate