Bash-like pipes in Python
Marko Rauhamaa
marko at pacujo.net
Thu Mar 17 08:44:08 EDT 2016
Sivan Greenberg <sivan at vitakka.co>:
> If I understand correctly, the binary right or overloading that's seen
> here can be applied to any other computational objects.
>
> I could also think of implementing it for input / output pipes
> overloading the __ror__ method with .communicate() method of the Popen
> object [0].
I'm thinking it's all of the above and more!
At the bottom is the generic pipelining of generators.
Then there's the special case of integrating external commands with the
generic framework:
cmd('cat /etc/passwd', stdin=None) | List
(Is "stdin=None" needed?)
Then there's the enriching of data formats. The line-based delineation
is old-school and unsafe, and should be considered for legacy only. The
internal data format is arbitrary Python object sequences, but
externally, JSON should be preferred. Thus, we'll need converters
from/to JSON.
What is still missing is the true generator lambdas:
produce_data | (
lambda name, value:
yield value) | \
consume_values
as in bash:
produce_data |
while read name value; do
echo $value
done |
consume_values
Marko
More information about the Python-list
mailing list