Getting values out of a CSV

Daniel no at no.no
Fri Jul 13 01:10:17 EDT 2007


On Fri, 13 Jul 2007 05:59:53 +0300, <CarpeSkium at gmail.com> wrote:

>
> How do I access the value in the second row in the first position of a
> CSV? Or the 3rd row, in the fifth position?
>
> a,b,c,d,e,f,g,h,i
> j,k,l,m,n,o,p,q,r
> r,s,t,v,w,x,y,z
>
> I'd want to get at "j" and "w". I know I can do
>
> import csv
> reader = csv.reader(open("some.csv", "rb"))
> for row in reader:
> print row[0]
>
> to get the first value in EVERY row, but I don't want that. Thanks for
> the help.
>

data = [row for row in csv.reader(open('some.csv', 'rb'))

then you can access like so:

>>> data[1][4]
'n'
>>> data[0][0]
'a'
>>> data[2][0]
'r'

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Python-list mailing list