Is this format of file standard one? If so? you can get all your float values with another technic.
So, here is the code:
str = """ ADDITIONAL DATA
Tip Rotation (degrees)
Node , UR[x] , UR[y] , UR[z]
21 , 1.0744 , 1.2389 , -4.3271
22 , -1.0744 , -1.2389 , -4.3271
53 , 0.9670 , 1.0307 , -3.8990
54 , -0.0000 , -0.0000 , -3.5232
55 , -0.9670 , -1.0307 , -3.8990
Mean rotation variation along blade
Region , Rotation (degrees)
Partition line 0, 7.499739E-36
Partition line 1, -3.430092E-01
Partition line 2, -1.019287E+00
Partition line 3, -1.499808E+00
Partition line 4, -1.817651E+00
Partition line 5, -2.136372E+00
Partition line 6, -2.448321E+00
Partition line 7, -2.674414E+00
Partition line 8, -2.956737E+00
Partition line 9, -3.457806E+00
Partition line 10, -3.995106E+00
"""
arr = str.split()
for index in enumerate(arr):
print index # just to see the list
start = 59 # from this position the numbers begin
step = 4 # current number is each fourth
ar = []
for j in range(start, len(arr), step):
ar.append(arr[j])
floatAr = []
# or you can use this expression instead of the following loop
# floatAr = [float(x) for x in ar]
for n in range(len(ar)):
floatAr.append(float(ar[n]))
print floatAr
At the end you will recive a list called floatAr with all your float values. You can add try-except block for better usability.
Or, alternatively, if you want to use regex, here is the code:
<!--language:python -->
str = """ ADDITIONAL DATA
Tip Rotation (degrees)
Node , UR[x] , UR[y] , UR[z]
21 , 1.0744 , 1.2389 , -4.3271
22 , -1.0744 , -1.2389 , -4.3271
53 , 0.9670 , 1.0307 , -3.8990
54 , -0.0000 , -0.0000 , -3.5232
55 , -0.9670 , -1.0307 , -3.8990
Mean rotation variation along blade
Region , Rotation (degrees)
Partition line 0, 7.499739E-36
Partition line 1, -3.430092E-01
Partition line 2, -1.019287E+00
Partition line 3, -1.499808E+00
Partition line 4, -1.817651E+00
Partition line 5, -2.136372E+00
Partition line 6, -2.448321E+00
Partition line 7, -2.674414E+00
Partition line 8, -2.956737E+00
Partition line 9, -3.457806E+00
Partition line 10, -3.995106E+00"""
regex = '\s-?[1-9]+[0-9]*.?[0-9]*E-?\+?[0-9]+\s?'
import re
values = re.findall(regex, str)
floatAr = [float(x) for x in values]
print floatAr
By the way, here is a good on-line regex checker for python pythex