Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: CSV out of range (http://www.velocityreviews.com/forums/t955109-re-csv-out-of-range.html)

Anatoli Hristov 12-04-2012 01:02 PM

Re: CSV out of range
 
The issue is now solved I did:

for x in mylist:
try:
sku.append(x[4])
except IndexError:
pass

Thank you for your help

Anatoli

Neil Cerutti 12-04-2012 01:58 PM

Re: CSV out of range
 
On 2012-12-04, Anatoli Hristov <tolidtm@gmail.com> wrote:
> The issue is now solved I did:
>
> for x in mylist:
> try:
> sku.append(x[4])
> except IndexError:
> pass
>
> Thank you for your help


Optionally:

for x in mylist:
if len(x) >= 4:
sku.append(x[4])

But do you really need to save the whole file in a list first?
You could simply do:

for record in csvreader:
if len(record) >= 4:
sku.append(record[4])

Or even:

sku = [record[4] for record in csvreader if len(record) >= 4]

--
Neil Cerutti

Anatoli Hristov 12-04-2012 02:38 PM

Re: CSV out of range
 
On Tue, Dec 4, 2012 at 2:58 PM, Neil Cerutti <neilc@norwich.edu> wrote:
> On 2012-12-04, Anatoli Hristov <tolidtm@gmail.com> wrote:
>> The issue is now solved I did:
>>
>> for x in mylist:
>> try:
>> sku.append(x[4])
>> except IndexError:
>> pass
>>
>> Thank you for your help

>
> Optionally:
>
> for x in mylist:
> if len(x) >= 4:
> sku.append(x[4])
>
> But do you really need to save the whole file in a list first?
> You could simply do:
>
> for record in csvreader:
> if len(record) >= 4:
> sku.append(record[4])
>
> Or even:
>
> sku = [record[4] for record in csvreader if len(record) >= 4]
>
> --
> Neil Cerutti


Thanks Neil,

I'm still testing it - just trying to clean the things out and be sure
that I can do all of the stuff :)

I will create a list only of the products I have in the DB and will
compare them for prices stock etc... so the list will be smaller :)

Thanks again

Anatoli


All times are GMT. The time now is 08:37 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.