[bip] replacing those shell scripts ... the PipeChain

Matt Dimmic reg at plaguerats.net
Thu May 7 06:59:54 PDT 2009


James,

Are you familiar with the pipes module in the Python standard library? I
don't have experience with it myself, but it seems to smooth out the bumps
you mention:

http://www.doughellmann.com/PyMOTW/pipes/index.html

-Matt

On Thu, May 7, 2009 at 8:46 AM, James Casbon <casbon at gmail.com> wrote:

> So I often want to use the unix toolchain to get a quick idea of some
> data.  You know, grep this, cut that, sort, etc.  I often find myself
> thinking that I won't use python because writing all those Popen(blah,
> stdout=PIPE) is just too verbose.  However, this means that the
> migration from shell script to python script has an annoying little
> little bump.
>
> So, without further ado, I present a little helper called PipeChain.
> This allows this kind of code:
>
> chain = PipeChain('grep ^x', 'cut -d" " -f2-3', 'sort', 'uniq -c')
>
> # use on a file
> proc = chain(file('input1.txt), file('output1.txt'))
> proc.wait()
>
> # or get a handle on the results
> proc = chain(file('input1.txt))
> proc.stdout.read()
>
>
> I have attached the file. I need one bit of help though - it would be
> nice to be able to pass in an iterable to use as the input_handle.
> subprocess either wants a proper handle, or PIPE.  How can you stream
> an iterable into a subprocess.PIPE without blocking?
>
> cheers,
> James
>
> _______________________________________________
> biology-in-python mailing list - bip at lists.idyll.org.
>
> See http://bio.scipy.org/ for our Wiki.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/biology-in-python/attachments/20090507/55944a88/attachment.htm 


More information about the biology-in-python mailing list