Considering that the file only has data in the format mentioned, we can turn it into a list of lists list comprehension .
Using best practices to open and manipulate files, the code to process this data looks like this:
with open('dados.txt', 'r') as f:
results = [[float(entry) for entry in line.split()] for line in f.readlines()]
print(results)
Result
[[0.435, 0.8798, 0.0099, 1.0], [0.4375, 0.8674, 0.009, 1.0], [0.44, 0.8682, 0.0082, 1.0]]
How It Works
First iterate in all rows of the file in for
outermost. For each line of the file, the split
(of the string) is executed to separate the values in a new list used by the internal for
. Then the function float
does the string cast to float.