Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34223 > unrolled thread

Re: CSV out of range

Started byAnatoli Hristov <tolidtm@gmail.com>
First post2012-12-04 13:36 +0100
Last post2012-12-04 13:36 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: CSV out of range Anatoli Hristov <tolidtm@gmail.com> - 2012-12-04 13:36 +0100

#34223 — Re: CSV out of range

FromAnatoli Hristov <tolidtm@gmail.com>
Date2012-12-04 13:36 +0100
SubjectRe: CSV out of range
Message-ID<mailman.459.1354624618.29569.python-list@python.org>
On Tue, Dec 4, 2012 at 12:31 PM, Thomas Bach
<thbach@students.uni-mainz.de> wrote:
> Hi there,
>
> Please be a bit more precise…
>
> On Tue, Dec 04, 2012 at 12:00:05PM +0100, Anatoli Hristov wrote:
>>
>> The problem comes when I try to index the SKU array and the field is
>> empty
>
> Can you provide an example for that?
>
>> and it seems that there I have empty array, I wanted to ignore the
>> empty arrays using if statement, but it does the same.
>
> Please provide a small, runable example with the actual code you tried
> that raises the exception and the complete trace back.
>
> Regards,
>         Thomas Bach.
> --
> http://mail.python.org/mailman/listinfo/python-list

Ok as I said I run a small script, here it is:

>>> import csv
>>>
>>> file = open("ShopPrices.csv", "rbU")
>>> reader = csv.reader(file, delimiter=";")
>>> mylist = []
>>> for i in reader:
...     mylist.append(i)
...
>>> mylist[543]
['19ITN992575', '19I', 'TN', '992575', 'RAB-UP-750-H3', 'Triton 19"
heavy duty 150kg shelf plate 750mm 1U black', '39,93', '0', '', '',
'', '', '', '', '', '', '', '', '']
>>> sku = []
>>> for x in mylist:
...     sku.append(x[4])
...
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
IndexError: list index out of range

>>> sku[43]
'PDM2332IEC-3P30R-3'
>>>

It appends all the data till it comes one SKU with empty record ("") .
I tried to use tey and except, but still the same

Thanks

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web