On 6/5/2014 5:53 AM, Marko Rauhamaa wrote:
Chris Angelico <ros...@gmail.com>:

If the standard streams are so crucial, why are their most obvious
interfaces insignificant to you?

I want the standard streams to consume and produce bytes.

Easy. Read the manual entry for stdxxx. "To write or read binary data from/to the standard streams, use the underlying binary buffer object. For example, to write bytes to stdout, use sys.stdout.buffer.write(b'abc')" To make it easy, use bound methods.

myfilter.p
----------
import sys
sysin = sys.stdin.buffer.read
sysout = sys.stdout.buffer.write
syserr = sys.stderr.buffer.write

<filter code with calls to sysin, sysout, syserr.>
---

The same trick of defining bound methods to save both writing and execution time is also useful for text filters when you use sys.stdin.read, etc, more than once in the text.

When you try this, please report the result, either way.

> I do a lot of  system programming and connect processes to each other
> with socketpairs, pipes and the like. I have dealt with plugin APIs
> that communicate over stdin and stdout.

Now you know how to do so on Python 3.

Python is clearly on a crusade to make *text* a first class system
entity. I don't believe that is possible (without casualties) in the
linux world. Python text should only exist inside string objects.

You are clearly on a crusade to push a falsehood. Why?

On Windows and, I believe, Mac, utf-16 encoded text (C widechar type) *is* a 'first class system entity. The problem Python has with *nix is getting text bytes from the system in an unknown or worse, wrongly-claimed encoding. The Python developers do their best to cope with the differences and peculiarities of the systems it runs on.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to