Python as a scripting language. Alternative to bash script?

Chris Rebert clp2 at rebertia.com
Wed Jul 7 14:27:07 EDT 2010


On Wed, Jul 7, 2010 at 8:31 AM, Michael Torrie <torriem at gmail.com> wrote:
> On 07/06/2010 09:34 PM, Chris Rebert wrote:
>> On Tue, Jul 6, 2010 at 6:40 AM, Michael Torrie <torriem at gmail.com> wrote:
>>> While it's possible to set up pipes and spawn programs in parallel to
>>> operate on the pipes, in practice it's simpler to tell subprocess.Popen
>>> to use a shell and then just rely on Bash's very nice syntax for setting
>>> up the pipeline.
>>
>> Until there's a Python variable involved that is, unless you want to
>> overlook all the edge cases or do the escaping all by yourself (and
>> then pray you did it right).
>
> Very good point.  This is a problem that the pipes module suffers from
> as well.
>
> Although we learned in the other thread on escaping SQL statements that
> escaping is faster, easier and just as safe as other parameterization
> mechanisms.  Uh huh.
>
> Back on target, a library similar to pipes that was safe (pipes is not)
> and had a pythonic syntax would be cool.  pipes module works alright,
> syntax wise, but it's not a clean syntax.

Actually, your original post inspired me to take a crack at writing
something like that yesterday:
http://rebertia.com/code/subproc_pipelines.py

Thoughts anyone? (Written on a whim, so no tests or docs at present.)

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list