perl to python

Kirk Job-Sluder kirk at eyegor.jobsluder.net
Tue May 11 15:25:53 EDT 2004


On 2004-05-11, Ville Vainio <ville at spammers.com> wrote:
> The things you usually do with the non-python tools are trivial, and
> trivial things have the habit of being, well, trivial in Python too.

I've not found this to be the case due to Python's emphasis on being
explicit rather than implicit.  My emulation of 
"perl -pi -e" was about 24 lines in length.  Even with the improvement 
there is still 10 times as many statements where things can go wrong.

It is really hard to be more trivial than a complete program in one
command line.

> You can always implement modules to do the tasks you normally use sed
> or awk for. I never saw much virtue in using the most specialized (or
> crippled, if you wish) tool possible. Not even if it's "optimized" for
> the thing. Actually, I tend to think that Python has to some extent
> deprecated that part of the Unix tradition.

However, that raises its own host of problems such as how do you import
the needed modules on the command line?  What do you do when that module is not
available?  What do you do when you need additional functionality that
takes one line in awk but a major rewrite in python?

It's a matter of task efficiency.  Why should I spend a half hour doing
in python something that takes 1 minute if you know the right sed, awk
or perl one-liner?  There is a level of complexity where you are better
off using python.  But why not use a one-liner when it is available?

> And yes, I'm aware that I'm exposing myself to some serious flammage
> from "if it was good enough for my grandad, it's good enough for me"
> *nix crowd. Emotional attachment to various cute little tools is
> understandable, but sometimes it's good to take a fresh perspective
> and just let go.

Write me a two-line script in python that reads a character delimited
file, and printf pretty-prints all of the records in a different order. 

Sometimes, a utility that uses an implicit loop over every line of a
file is useful.  That's not emotional attachment, it's plain common
sense. 




More information about the Python-list mailing list