What is Python?

Alex Martelli aleaxit at yahoo.com
Mon Sep 18 08:38:10 EDT 2000


"Tim Hammerquist" <tim at degree.ath.cx> wrote in message
news:slrn8sbp5c.21l.tim at degree.ath.cx...
> Grant Griffin <g2 at seebelow.org> wrote:
> > p.s.  In case you haven't noticed, this "ly y'rs" schtick is an yet
> > another good reason to switch. <wink>
>
> Actually, I find myself preferring constant flames to all this "ly y'rs"
> and "<wink>" stuff.  Maybe I'm just not in the spirit.

Although I think of myself as an ex-Perl'ist, I second the motion -- too
much cutesy posturing around here.  Monty Python's humour wasn't like
this, IMHO...


> As a matter of interest, anyone want to convert the following code to
> Python?
>
> perl -npe 'next unless /\bjudea/i && /\bfront\b/i' /scripts/movies/brian/*

Idiomathic Python conversion would probably be:


import re
import fileinput

judea=re.compile(r'\bjudea',re.I)
front=re.compile(r'\bfront\b',re.I)

for line in fileinput.input('/scrips/movies/brian/*'):
    if judea.search(line) and front.search(line):
        print line


As one of Python's aesthetic principles is "explicit is better
than implicit", one wouldn't want to rely on implicit looping
and/or printing.  Besides, it's just not a one-liner-culture.
(It's not that hard to make an interpreter version optimized for
one-liners, if you're really keen about it, of course).

Incidentally, I think I'd have gone for concision in the Perl
version -- definitely a value in ITS culture -- by using
    print if
in lieu of the more verbose
    next unless
(and the no-implicit-printing flag), although this would no
doubt have the unfortunate side effect of making the code a
lot more transparent -- but a saving of FOUR characters is
just too good to pass up, isn't it?


Alex





More information about the Python-list mailing list