On Thu, 7 Mar 2002, Bob Miller wrote:

> The Python requires explicit naming of the input line, explicit naming
> of the fact that the match succeeded, an explicit string to int
> conversion, and explicit naming of the matched substrings.  And
> timestamp.groups() is counterintuitive as a way to access the
> substrings.
> 
> Perl: one line, no extra names.
> Python: four lines, four extra names (timestamp, hr, min, and sec).
> 
> OTOH, I can see that a non-Python programmer could read the Python
> easier than a non-Perl programmer could read the Perl.  (What's <>?
> What's $1?  What string is the regexp matching?)
>
And there's the maintenance factor too, if the PHB comes along and decrees
that from now on we'll be using elbonian date formats it's a lot easier
for someone else to change it if it's written in python.

> > One feature of python that I've become quite fond of lately is the ability
> > to hand the string interpolation operator a dictionary and have it
> > properly format stuff without messing around with print tuples.
> 
> Yeah, there's a minimum format complexity for which that's worthwhile.
> I didn't judge it worthwhile here.
> 
> I think it would go like this.

Couple of minor syntax bugs.
> 
>       out_strings = {
>           len: len(ftimes),
>           mean: time_format(ftimes.mean()),
>           min: time_format(ftimes.minimum()),
>           max: time_format(ftimes.maximum()),
>           std_dev: time_format(ftimes.std_deviation())
>       }

dictionary keys can't be mutable objects, so 'len' : ...,

>       print "%{len}s frames" % out_strings
>       print "fastest: %{min}s" % out_strings,
>       # ...
> 
those would be parens in the delimiter and you can do multiple lines by
using a triple quoted string

"""%(len)s frames by %(host)s
fastest: %(min)s mean: %(mean)s ....




But those are probably the result of typing code straight into email ;-)


http://www.efn.org/~laprice        ( Community, Cooperation, Consensus
http://www.opn.org                 ( Openness to serendipity, make mistakes
http://www.efn.org/~laprice/poems  ( but learn from them.(carpe fructus ludi)

Reply via email to