Hi

Having trouble getting this started. I wan't to read lines of data from my file, which has the current contents

Scores.txt -

Names             Difficulty                    Scores                Totals
Mark        Smith           2.5         6.0  5.0  5.5  5.5  6.5  6.0  6.5    44.25
John        Andrews         2.8         5.5  5.5  6.0  4.5  6.0  5.5  5.0    46.20

and using this code, read the file to extract certain fields for calculation

def main(): 
    fileIn = open( "scores.txt", "r") 
    lineIn = fileIn.readline() 
    while len(lineIn) != 0: 
        print lineIn 
        lineIn = fileIn.readline() 

main()

What would be a simple way to extract a field like 6.0 from scores to be used in my final calculation?

Should I define each field like 'scores' ' names' ' difficulty' in the code itself? or read from the whole file?

Any help would be appreciated

You can try to split each line using

tokens = lineIn.split()
if len(tokens)==4:
   continue # skip the header
# For subsequent line
firstname = tokens[0]
lastname  = tokens[1]
...
totals    = float(tokens[-1])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.