[Python-ideas] shutil.runret and shutil.runout
anacrolix at gmail.com
Sun Feb 26 16:10:00 CET 2012
I did recently see "pyp" touted as a Python-like sed/awk.
I guess this stuff always comes down to what you're used to. To me it is
insane to be still using Perl yet I prefer perl regex over posix anyday :)
On Feb 26, 2012 10:03 PM, "Stephen J. Turnbull" <stephen at xemacs.org> wrote:
> Serhiy Storchaka writes:
> > Yes, I want this in Python:
> > readall(cmd('cut -d: -f3 $file', file='/etc/passwd') | cmd('sort -n') |
> cmd('tail -n5'))
> > or
> > cmd('cut', '-d:', '-f3', '/etc/passwd').pipe('sort', '-n').pipe('tail',
> > or something similar.
> But you can already do
> sorted([l.split(":") for l in open('/etc/passwd')])[-5:]
> (and I don't really care whether you were being ironic or not; either
> way that one-liner is an answer<wink/>).
> Actually, I wrote that off the top of my head and it almost worked.
> The problem I ran into is that I'm on a Mac, and there was a bunch of
> cruft comments (which don't contain any colons) in the beginning of
> the file. So I got a list index out of range when accessing the split
> line. In this case, cut | sort | tail would produce the expected
> output. But cut | sort | head would just produce garbage (the leading
> comments in sorted order). So the failure modes differ. It might be
> useful for people used to shell failure modes.
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas