[Python-Dev] pipe syntax for sequential data

Bob Ippolito bob at redivi.com
Tue Apr 13 12:39:55 EDT 2004

On Apr 13, 2004, at 12:10 PM, Josiah Carlson wrote:

>>> This recipe proposes an alternative syntax for sequential data
>>> processing functions, that reflects unix shell pipe syntax. Here is 
>>> an
>>> example:
>>> bash_users = ( file('/etc/passwd') | grep('/bin/bash') | aslist )
>>> I don't know if this idea was already explored before; hope this can
>>> be useful. For details and sample code please see link above.
>> If you're serious about this, you'll need to write up a PEP and push 
>> it
>> forward.
> While some would call Python a 'scripting language', I think that using
> pipes in such a way in Python would be counter to the zen:
> "There should be one-- and preferably only one --obvious way to do it."

But there are others, such as "Although practicality beats purity".

This case is already pretty practical using existing syntax though:
[line for line in file('/etc/passwd') if '/bin/bash' in line]

Though it does pollute the locals..

> We can already use list comprehensions, filter and friends (or ifilter 
> as used by
> MK), when such functionality is desired.  IMO, just because you can 
> make
> a language  behave like a command line, does not necessarily mean that
> you should.

Of course you should, but that doesn't mean it should be __builtin__.


More information about the Python-Dev mailing list