We help IT Professionals succeed at work.
Get Started

read csv into list in python

opensourcenija
on
1,126 Views
Last Modified: 2012-05-08
I am trying to read the content of my text file into and display the result... the test file is saved in this format

craig , 10 , 10 , 19 ,89
ben, 30 , 39 , 90 , 88
tom, 47,56,67,66,66

and so on... I am trying to the record as shown below

Name: craig
Score 1: = 10
Score 2: = 10
Score 3: = 19
Score 4: = 89

for all the rcord in the list and i keep errors. below is the code.

This record will be shown for every line in the text file
import csv

holder = []


f = csv.reader(open('records.txt' ,"rb"), delimiter =",")
while True:
    #lines = f.readline()
    for line in f:
        hold=holder.append(line)
        print holder[0]

        #print holder
        #print line
    print (" Student Name : %s" , holder[0])
    print (" Score 1 : %s" , holder[1])
    print (" Score 2: %s" , holder[2])
    print (" Score 3 : %s" , holder[3])
    print (" Score 4 : %s" ,holder[4] )
    break
    f.close()#close the file
    print "Done..."

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE