[Python-Dev] pipe syntax for sequential data (original) (raw)
Bob Ippolito bob at redivi.com
Tue Apr 13 12:39:55 EDT 2004
- Previous message: [Python-Dev] pipe syntax for sequential data
- Next message: [Python-Dev] pipe syntax for sequential data
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
bashusers = ( 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.
-bob
- Previous message: [Python-Dev] pipe syntax for sequential data
- Next message: [Python-Dev] pipe syntax for sequential data
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]