How would I write this perl script in python?
David Bolen
db3l at fitlinxx.com
Mon Nov 5 22:41:34 EST 2001
David Bolen <db3l at fitlinxx.com> writes:
(following up to myself)
> import re, fileinput
>
> for line in fileinput.input():
>
> match = re.search(r'^(\w+\s+)(\-*\d+\.\d+)(\s+)(\-*\d+\.\d+)$',line)
> if match:
> val = match.group(2) - 0.775
> print "%s%s%s%s" % (match.group(1),val,
> match.group(3),match.group(4))
> else:
> print
Nick's similar followup showed a bug in my sample (knew I should have
simulated some input :-)). You need to convert match.group(2) to a
floating point value for the calculation - e.g.,
"float(match.group(2))"
--
-- David
--
/-----------------------------------------------------------------------\
\ David Bolen \ E-mail: db3l at fitlinxx.com /
| FitLinxx, Inc. \ Phone: (203) 708-5192 |
/ 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
\-----------------------------------------------------------------------/
More information about the Python-list
mailing list