Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: CSV out of range

Reply
Thread Tools

Re: CSV out of range

 
 
Anatoli Hristov
Guest
Posts: n/a
 
      12-04-2012
On Tue, Dec 4, 2012 at 12:31 PM, Thomas Bach
<(E-Mail Removed)-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: CSV out of range Anatoli Hristov Python 2 12-04-2012 02:38 PM
Re: CSV out of range Thomas Bach Python 0 12-04-2012 11:31 AM
CSV out of range Anatoli Hristov Python 0 12-04-2012 11:00 AM
csv read clean up and write out to csv Sacha Rook Python 2 11-02-2012 07:51 PM
csv writerow creates double spaced excel csv files Michal Mikolajczyk Python 0 02-13-2004 08:38 PM



Advertisments