Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'that?': 0.05; "'',": 0.07; 'raises': 0.07; 'script,': 0.09; 'cc:addr :python-list': 0.10; 'index': 0.13; 'ignore': 0.13; 'dec': 0.15; "'0',": 0.16; 'appends': 0.16; 'csv': 0.16; 'indexerror:': 0.16; 'mylist': 0.16; 'subject:CSV': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'bit': 0.21; 'import': 0.21; 'received:209.85.214.174': 0.21; '"",': 0.22; 'back.': 0.22; 'trace': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; '(most': 0.27; 'small,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'actual': 0.28; 'run': 0.28; 'record': 0.28; '+0100,': 0.29; 'arrays': 0.29; 'url:mailman': 0.29; 'array': 0.29; "skip:' 10": 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; "skip:' 20": 0.32; 'url:listinfo': 0.32; 'traceback': 0.33; 'problem': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'list': 0.35; 'same.': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'wanted': 0.36; 'url:org': 0.36; 'does': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'there,': 0.38; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'range': 0.60; 'thomas': 0.62; 'provide': 0.62; 'more': 0.63; 'here': 0.65; 'heavy': 0.83; 'plate': 0.84 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:content-transfer-encoding; bh=0wHgL5DPWfqEJn2MtLbDdlm0Q4Vy+FkB+Be6RDAw2QQ=; b=gLQb+acCxSESB/lSWLD0WnLtl6373JGFj077W2H/akXiOvp/8SMbxpUFweTpHSL90k UbDud69Lk5AAemsmp+ZMK5+Zj0y9pUnk1wvWfjn2xvGIrW5G3gcPYo38Fql7+iodVIfj nfDc5s0OwC9zBy0NVQTkkyq/Bqsinx721zHpkQU0i6eE/OwTHECJne4ekM/oBhbD4MiO /JX3dU80i6HMacLjxRff7H3BVoXzbB1EYXfbwR2/apBj469EXQ+gC4jnEB/JyVGJK7Um eva5cK2BUMSjRu5sll38oOI3PKXwrjj6bXMEjPNdauO7pb9cI0Hgt6JyNqDaTn7VUYvU igoQ== MIME-Version: 1.0 In-Reply-To: <20121204113102.GA4194@taris.box> References: <20121204113102.GA4194@taris.box> Date: Tue, 4 Dec 2012 13:36:55 +0100 Subject: Re: CSV out of range From: Anatoli Hristov To: Thomas Bach Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354624618 news.xs4all.nl 6949 [2001:888:2000:d::a6]:43302 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34223 On Tue, Dec 4, 2012 at 12:31 PM, Thomas Bach wrote: > Hi there, > > Please be a bit more precise=E2=80=A6 > > 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 =3D open("ShopPrices.csv", "rbU") >>> reader =3D csv.reader(file, delimiter=3D";") >>> mylist =3D [] >>> 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 =3D [] >>> for x in mylist: ... sku.append(x[4]) ... Traceback (most recent call last): File "", 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