I need to extract data from lines of a text file. The data is name and scoring information formatted like this:
Feature_Locations:
- { x:9.0745818614959717e-01, y:2.8846755623817444e-01,
z:3.5268107056617737e-01 }
- { x:1.1413983106613159e+00, y:2.7305576205253601e-01,
z:4.4357028603553772e-01 }
- { x:1.7582545280456543e+00, y:2.2776308655738831e-01,
z:6.6982054710388184e-01 }
- { x:9.6545284986495972e-01, y:2.8368893265724182e-01,
z:3.6416915059089661e-01 }
- { x:1.2183872461318970e+00, y:2.7094465494155884e-01,
z:4.5954680442810059e-01 }
This file is generated by another software. Basically I want to get that data back in this program and i want to save them in different other files for examples "axeX.txt" "axeY.txt" "axeZ.txt"
I have try this
import numpy as np
import matplotlib.pyplot as plt
import re
file = open('data.txt', "r")
for r in file:
y = re.sub("- {", "",r).split()
tt = y[:2]
zz = tt
st = re.findall('\d+', r)
print st
file.close()
Is there a better way or I am doing it wrong ?