How would I write this perl script in python?

Igor Stroh igor.stroh at wohnheim.uni-ulm.de
Mon Nov 5 17:09:02 EST 2001


On Mon, 05 Nov 2001 22:15:06 +0100, "Aaron Ginn" <aaron.ginn at motorola.com>
wrote:


> I rarely use Perl except in cases where it is not obvious how to do
> something in Python that I already know how to do in Perl.  I'm curious
> what the best way to rewrite the following Perl script in Python is.

[perl script]
 
> In the above script, I subtract 0.775 from the value found in $2 and
> replace $2 with the new value ($val).

I'm not quite sure what you are trying to do, since I can't even read
perl code, but have a look at re.sub:

>>> import re
>>> foo = "some data we dont really need *important stuff* useless string"
>>> bar = re.sub(".*\*(.*)\*.*","now we have only \\1", foo)
>>> bar
'now we have only important stuff'


hope that helps,
Igor



More information about the Python-list mailing list