How to designate sys.stdout for binary output in win32?

zERo zERo at nowhere.com
Mon May 5 01:13:12 EDT 2003


sjmachin at lexicon.net (John Machin) wrote in
news:3eb56a9d.1643312 at news.lexicon.net: 

> On Sun, 04 May 2003 10:50:16 GMT, "C.M. Lim" <cmlim at ieee.org> wrote:
> 
>>I need to print strings as-is, control/escape chars et al, to
>>sys.stdout in a win32 python environment (in Unix, this would be
>>trivial). 
>>
>>I found some sample code that uses msvcrt module to explicitly set the
>>BINARY mode, as follows:
> [snip]
>>but on my system (Python2.1.1), sys.stdout is a PyShell.PseudoFile 
>>instance, and does not have a fileno() method.
>>
> 
> Please let us know what piece of software you expect to act on the
> escape sequences and control characters that you wish to send to
> sys.stdout.
> 
> If it is Pyshell, then you should be addressing your question to the
> PyShell maintainer(s).
> 
> If it is not PyShell, but some other gadget, like a
> green-screen-terminal emulator -- similar to the good ol' ANSI.SYS
> console device driver on MS-DOS -- then it seems an incredibly good
> bet that you may have to run Python at the command line.
> 
 

My current application uses Python to generate an image.  Instead of
creating a file, it could be used to send raw output.  By using
appropriate html headers, I could use it as a CGI app and have it
display directly in a browser.  Thus, the requirement of 'binary'
output to sys.stdout, so the browser can act upon it.

I can think of other uses this may have, an example would be akin
to Unix filter apps, where the Python app would take the input and
pass along modified output (albeit in 'binary' form) as stdout.

After reading your post, it got me thinking.  I now believe that the
indication I got that sys.stdout is a Pyshell.PseudoFile instance
comes from the fact that I tried to simplify it into a test-case and
*WAS* checking it out in a PyShell, and hence would receive that
indication.  Uugggh!! back to square one...

Thanks for your input.  BTW, it should not matter what the receiving
app is, so long as the previous stage sends data out on stdout and the
receiving app receives it on stdin, right???

CM

 





More information about the Python-list mailing list