Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.043 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'try:': 0.07; 'len(x)': 0.09; 'cc:addr:python-list': 0.10; 'dec': 0.15; 'did:': 0.16; 'etc...': 0.16; 'indexerror:': 0.16; 'subject:CSV': 0.16; 'wrote:': 0.17; 'trying': 0.21; 'received:209.85.214.174': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'testing': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'record': 0.28; "i'm": 0.29; 'stuff': 0.30; 'file': 0.32; 'could': 0.32; 'received:google.com': 0.34; 'thanks': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'compare': 0.36; 'smaller': 0.36; 'stock': 0.36; 'thank': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'sure': 0.38; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'save': 0.61; 'prices': 0.62; 'products': 0.70; 'first?': 0.84; 'neil': 0.84; 'do:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OQAwSycJqFIn7KJnclqZQmYxt85iBgs68fF+oz63uGw=; b=IRzDuununInLd0MElUjwO/+rZKK90pFaRHUPrgYDv41pbQZXWqAZck/IRKdN0Izh0T WwlirFjc2VGISqal3coQ7tRunEHvRY+pK7m9hfoRgX2rRcgcY/8O+826JsxmaXabozK4 jkoAf0E/oOKLApIAymvKw21+Lho4wlJUmndbuk66KYK6u8tnv1HLFK+iIZCisTczJ3zV NJunk45l44N9DjQzbLtlxZfaANOkbIXglSWwMh/KW2jfQH0Y9tCyVz1l11BWxujFY3OF vsEtOoig+0YOtiiEJBVNOq4OSZJLuuD9oTSCk06qFfOXWXXL3WPaSRYmMgSKHkBk2Cdy LjnQ== MIME-Version: 1.0 In-Reply-To: References: <20121204113102.GA4194@taris.box> Date: Tue, 4 Dec 2012 15:38:11 +0100 Subject: Re: CSV out of range From: Anatoli Hristov To: Neil Cerutti Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354631894 news.xs4all.nl 6856 [2001:888:2000:d::a6]:44158 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34231 On Tue, Dec 4, 2012 at 2:58 PM, Neil Cerutti wrote: > On 2012-12-04, Anatoli Hristov 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