Closed gavinwahl closed 9 years ago
So, to answer your question, run(a).pipe(run(a))
works.
Now, I want to group these issues here for "magic operators" like command > open(file)
and command | other_command
.
The main reason I'm reluctant to implement this is because programming operators have a very different meaning compared bash operator.
Let me give you an example: |
in programming is bit-wise or
. >
is greater than. They're semantically different, even though they look the same.
Another example: bash has 2>
and >
, now 2>
gets renamed to >>
because 2>
doesn't exist is python. But >>
has a meaning in bash (it means appending.)
Also, this makes the code look "magic" (or "rubyish" as you wish).
Another thing, someday I might implement && and ||, and do things like:
(pg_dump db1 && pg_dump db2) | grep table
So if we would have started implementing those "magic" operators, it would make sense to implement &
for this, because &&
doesn't exist in python. (Along with run('pg_dump', 'db1').and_('pg_dump', 'db2')
.) But how would we implement ||
? And is |
a pipe or a bash or
?
I actually intended >> to be the same as in sh, but I realized that's not necessary, you just open the file in append mode.
You don't need to convince me about the disadvantages of operator overloading. Maybe I'm confused about the scope of this library though. I thought it was supposed to be a stupid-simple way to build pipelines, not a implementation of sh in python.
In addition to
run(a).pipe(b)
, it'd be cool to dorun(a) | run(b)