How to print to stdout in binary
brianbird at my-deja.com
brianbird at my-deja.com
Thu Jul 6 05:49:27 EDT 2000
I've seen similar questions to this posted in other language forums,
but I've not seen anything for Python:
Does anyone know how to tell python to print the sys.stdout in binary
rather than plain text. It's mode is set as 'w' and I can't seem to
change it.
I'm experimenting with a cgi script which I want to output an image to
the browser so that the HTML file can have:
<IMG SRC="test.cgi">
and the resulting output of the script is an image.
I've currently got:
f = open("test.jpg","rb")
bytes = f.read()
f.close()
sys.stdout.print(bytes)
but I want the output to print in binary mode so that the image can be
displayed correctly. If I was printing to another file I could open it
with:
f2 = open("test2.jpg","wb")
f2.write(bytes)
f2.close()
so is there any way to do this with stdout?
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list