Why will this for loop not return one field from list rather than the list?

Posted by Dick Eshelman on Stack Overflow See other posts from Stack Overflow or by Dick Eshelman
Published on 2011-01-08T08:48:30Z Indexed on 2011/01/08 8:53 UTC
Read the original article Hit count: 218

Filed under:
|
|
|

import csv

"""sample row = 10/6/2010,73.42,74.43,72.9,74.15,2993500"""

filename_in = 'c:/python27/scripts/fiverows.csv'

reader = csv.reader(open(filename_in, "rb"), dialect="excel", delimiter="\t", quoting  =csv.QUOTE_MINIMAL)

for row in reader:  
    for item in row:  
        print 'row = ',row  
        print 'item  = ', item  

When you run this script and print the row you get the sample row returned in [] as a list. When you print the item you get the sample row as an unquoted string. Why do I not get each field ie, (10/6/2010), (73.42), etc. returned as an item? How do I return a single item?

© Stack Overflow or respective owner

Related posts about python

Related posts about list