I wrote a simple program to read some floats from a file:
line2 = f1.readline()
if "Totals" in line2:
cline = line2.strip()
csline= cline.split(" ")
zforcet = float(csline[7])
torquet = float(csline[8])
line2
in question is :
Totals 7.911647E+03 -1.191758E+03 7.532665E+03 4.137034E+00
My code works, but my question is this there a more obvious way to code this ?
I mean it is not at all obvious to me that the second real number on the line is csline[7]
and i could do this only after trail and error and printing out the contents of csline
. I am looking for a way to "read the second float" on a line directly.