piping out binaries properly

marduk usenet at marduk.letterboxes.org
Wed Oct 12 01:37:48 EDT 2005


On Wed, 2005-10-12 at 00:16 -0400, Mike Meyer wrote:
[...]
> It's not normal to write binary content to stdout - you normally write
> it to a file. Open the file with open(name, 'wb') to write binaries.
> 

It is interesting that as a "Unix consultant" you should make that
claim.  Especially since

>>> sys.stdout
<open file '<stdout>', mode 'w' at 0x2aaaaaac9198>
      ^^^^

Indeed there would be a lot of broken Unix systems out there if that
were not the case.

As for the OP, you may want to check how stdout is opened on your
system.  In Windows there are two "write" modes for files, 'w', and 'wb'
where apparently 'w' is text mode and 'wb' is binary.  You may want to
check what mode your stdout is in.  I don't have a Windows box handy
right now to verify.

> There doesn't appear to be any way to retroactively change the mode on
> a file. Which is probably a good thing.
> 
>     <mike-- 
> Mike Meyer <mwm at mired.org>
http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more
information.





More information about the Python-list mailing list