perl to python

Ville Vainio ville at spammers.com
Wed May 12 02:20:09 EDT 2004


>>>>> "Kirk" == Kirk Job-Sluder <kirk at eyegor.jobsluder.net> writes:

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

That's when you create a module which does the implicit looping. Or a
python script that evals the passed expression string in the loop.

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

As has been stated elsewhere, you can do the trick on the command
line. The effort to create the required tools only needs to be paid
once.

However, many times it won't matter whether the whole program fits on
the command line. I always do a script into a file and then execute
it. I just prefer a real editor to command history editing if
something goes wrong.

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

I think one should just analyze the need, implement the requisite
module(s) and the script to invoke the stuff in modules. The needs
have the habit of repeating themselves, and having a bit more
structure in the solution will pay off.

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

(Already done)

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

The virtual of the implicitness is still arguable.

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list