List index out of range, but list has enough elements

Nitin Pawar nitinpawar432 at gmail.com
Tue Nov 9 11:02:44 CET 2010


You may want to try a spilt if you are getting 8 different elements then it
will give you a list of those elements

On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamenț <costin.gament at gmail.com>wrote:

> Thank you for your timely response. Yes, I am sure "i" and "j" are
> from the same iteration. I should point out that "i" actually has 8
> elements and that str(i) gives a nice printout.
>
> On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel <stefan_ml at behnel.de>
> wrote:
> > Costin Gamenț, 09.11.2010 10:24:
> >>
> >> Hi, I am trying to read a string as csv, but I encountered an odd
> >> problem. Here's my code:
> >>
> >>        csvfile = csv.reader(datastr.split('\n'), delimiter=';')
> >>        r = ''
> >>        for i in csvfile:
> >>                for j in i:
> >>                        print j
> >>                print i[0]
> >>
> >> the "print j" statement works, but "print i[0]" returns "IndexError:
> >> list index out of range". Am I missing something?
> >
> > Are you sure the output you get from the "print j" is from the same loop
> > iteration as the "print i[0]"? Try adding "i" to the output.
> >
> > Stefan
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101109/dd139257/attachment.html>


More information about the Python-list mailing list