[Python-ideas] Running Python commands from a Shell

eryk sun eryksun at gmail.com
Fri Feb 1 22:02:56 EST 2019


On 2/1/19, Steven D'Aprano <steve at pearwood.info> wrote:
> On Fri, Feb 01, 2019 at 07:21:47PM -0600, eryk sun wrote:
>
>> As soon as  "pipe" is mentioned, anyone familiar with the REPL's
>> behavior with pipes should know that making this work will require the
>> -i command-line option to force interactive mode. Otherwise stdout
>> will be fully buffered. For example:
> [...]
>
> I wonder... could Python automatically detect when it is connected to
> pipes and switch buffering off?

In most cases we want full buffering when standard I/O is a pipe or
disk file. It's more efficient to read/write large chunks from/to the
OS.

In another message I saw -u mentioned to disable buffering. But that's
not sufficient. We need -i to force running the built-in REPL over a
pipe, and optionally -q to quiet the initial banner message.


More information about the Python-ideas mailing list