I have a text file like below. I want to read given values as a float list. After that I am going to do some calculations. I used split function and convertion to float. But I cannot convert first one and last one because those two has square brackets. ([ ]). it gave an error as below.
File format
[-1.504, 1.521, 1.531, 1.1579, -2.2976, 2.5927,... 1000 records]
[2.758, -0.951, -1.7952, 0.4255, 2.5403, 1.0233,... 1000 records]
[0.682, -2.205, 2.1981, 2.1329, 0.1574, -0.4695,... 1000 records]
Error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: [0.682
Code I used
F = open('XYZ.txt', 'r')
>>> for line in F:
... P = line.split(',')
... P
Can any one give me an idea how do I read that values into a float array like below.
X = [-1.504, 1.521, 1.531, 1.1579, -2.2976, 2.5927,... 1000 records]
Y = [2.758, -0.951, -1.7952, 0.4255, 2.5403, 1.0233,... 1000 records]
Z = [0.682, -2.205, 2.1981, 2.1329, 0.1574, -0.4695,... 1000 records]
Then I can call values like X[1], X[999]