En Mon, 02 Mar 2009 17:58:01 -0200, Bo Zhang <primroseb...@gmail.com> escribió:

I want to parse a file and do this :

    A  74.335 -86.474-129.317  1.00 54.12

then add space between -86.474 and -129.317. I can get the file with

    A  74.335 -86.474 -129.317  1.00 54.12

Use a regular expression:

py> import re
py> line = "A  74.335 -86.474-129.317  1.00 54.12"
py> re.sub(r"(\d)-(\d)", r"\1 -\2", line)
'A  74.335 -86.474 -129.317  1.00 54.12'

You many require r"(\d)-([\d\.])" if a number is allowed to start with a decimal point.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to