perl to python

Hornberger, Chris Chris.Hornberger at blackrock.com
Wed May 12 15:43:42 EDT 2004


First off, this isn't even remotely a slam, so I hope it's not taken as such.

My question is this.

Why bother with getting perl code translated into python code?

Perl is probably one of the best string manipulation and RegEx processors ever.

Python is probably one of the easist general purpose scripting languages ever.

They don't have to overlap. With Python's pipe handling there's little reason not to simply leave the perl code where it is and run it from an orchestration script in Python.

Perl is a pretty involved, terse and comprehensive wheel. Not sure I see the reasons to reinvent it. It's safe to say that a large majority of the people using perl are also working with it (writing in it).

$.02

*note - these are my observations from the environments I'm used to working in. your mileage may vary*

--------------------------
Chris Hornberger
Blackrock - 302.797.2318
chris.hornberger at blackrock.com

Card carrying MSDN member since 2004.
No, really. I've got the card to prove it.


-----Original Message-----
From: python-list-bounces+chris.hornberger=blackrock.com at python.org
[mailto:python-list-bounces+chris.hornberger=blackrock.com at python.org]On
Behalf Of Scott Schwartz
Sent: Wednesday, May 12, 2004 3:08 PM
To: python-list at python.org
Subject: Re: perl to python


Duncan Booth <me at privacy.net> writes:
> import sys
> for line in sys.stdin:
>     line = line[:-1].split('\t')
>     print "%s %s %s %s" % (line[3], line[2], line[1], line[0])

> While I agree with you that using the appropriate tool is preferred over 
> using Python for everything, I don't really see much to choose between the 
> Python and awk versions here.

1) Python throws an error if you have less than three fields,
requiring more typing to get the same effect.

2) Python generators on stdin behave strangely.  For one thing,
they're not properly line buffered, so you don't get any lines until
eof.  But then, eof is handled wrongly, and the loop doesn't exit.

3) There is no efficient RS equivalent, in case you need to read
paragraphs.

The simpler example

   for line in sys.stdin:
      print line

demonstrates the problem nicely.

$ python z
a
b
c
^D
a
 
b
 
c
 
foo
bar
baz
^D
foo
 
bar
 
baz
^D
^D
$ 

Explanations in the docs about buffering and readahead don't excuse
this poor result.  

$ awk '{print}'
a
a
b
b
c
c
^D
$
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list