Simple Python equivalent for the shell command

Michael Torrie torriem at gmail.com
Mon Nov 28 11:17:50 EST 2016


On 11/28/2016 08:55 AM, Michael Torrie wrote:
> Well Bash is really good at some things.  Piping commands together is
> one of those things.  Python can do such things but not in as compact a
> way.  For one Python has no quick way of interfacing with subprograms as
> if they were language-level constructs like Bash does.  But it still can
> do a lot of the same tasks that shell scripting does.  Read on.
> 
> In many respects, generators are the Python equivalent of pipes. See
> this: http://www.dabeaz.com/generators/, specifically
> http://www.dabeaz.com/generators/Generators.pdf

I should mention that the one thing that Python has no support for in
its generator methodology is the idea of having one execution unit that
can have both standard out and standard error pipes and communicate with
both at the same time. Bash can support arbitrary pipes I believe.
However even Bash's syntax is awkward, and I can't imagine a decent way
to do it in Python anyway.  Perhaps yielding a tuple.



More information about the Python-list mailing list