[Tutor] Fwd: arrangement of datafile

Dave Angel davea at davea.name
Thu Jan 9 13:23:13 CET 2014


On Thu, 9 Jan 2014 14:51:21 +0800, Amrita Kumari 
<amrita.g13 at gmail.com> wrote:
> days), I tried this code which you suggested (by saving it in a 
file):




> import csv
> with open('19162.csv') as f:
>    reader = csv.reader(f)
>    for row in reader:
>       print(row)
>       row[0] = int(row[0])
>       key,value = item.split('=', 1)
>       value = float(value)
>       print(value)

> and I got the output as:

> C:\Python33>python 8.py
> ['2', 'ALA', 'C=178.255', 'CA=53.263', 'CB=18.411', '', '', '', '', 
'', '', '',
> '', '', '']

So you can see that row is a list representing one line of the data 
file. Clearly item is intended to be one element of the list, such as 
row[2] or row [3]. Try it first by adding just the line 
    item=row [2]

Then figure how to make a loop over the items in the row.

-- 
DaveA



More information about the Tutor mailing list