I have a file that contains strings like this :
N7300 X-7.254 Y-40.839 A-89.74
N7301 X-7.002 Y-40.847 A-89.806
N7302 X-6.75 Y-40.855 A-89.873
N7303 X-6.511 Y-40.862 A-89.926
N7304 X-6.272 Y-40.868 A-89.979
The bold strings has negative numbers. I dont know how to read these numbers from the file.
I want to generate output like this :
[('N','7300'),('X','-7.254'), ('Y','-40.839') . . .]
import re
import sys
with open(r'/home/ruchir/Desktop/NewFolder/TEST.txt') as f:
lines=f.readlines()
lines=''.join(lines)
lines=lines.split()
a=[]
for i in lines:
match=re.match(r"([a-z]+)([0-9]*\.?[0-9]+)",i,re.I)
if match:
a.append(match.groups())
print a
I wrote this program that works fine but not for negative integers..!! Plzz help me, I'm new in Python...