Entry
How do I send binary data to stdout under windows?
How do I generate an image or other binary data in a cgi script on windows?
Jun 13th, 2002 15:25
Michael Chermside,
On unix, there is no difference between text mode and binary mode files,
but on Windows (and some others as well), there is. If you are opening a
file, you can use mode 'r' vs 'rb' or 'w' vs 'wb' to switch between text
and binary modes. But sys.stdout is opened FOR you before the program
starts, so how can you change the mode of that? This is a particularly
common problem in writing cgi scripts to generate images or other binary
data.
The solution is nicely described in an entry in the Python Cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443