Path: csiph.com!usenet.pasdenom.info!news.albasani.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'false.': 0.07; 'valueerror:': 0.07; 'dvi': 0.09; 'loop.': 0.09; 'typeerror:': 0.09; 'index': 0.13; '(empty': 0.16; 'csv': 0.16; 'csv,': 0.16; 'error"': 0.16; 'incremented': 0.16; 'indexerror:': 0.16; 'iterating': 0.16; 'lcd': 0.16; 'match:': 0.16; 'subject:compare': 0.16; 'certainly': 0.17; 'posted': 0.22; 'sets': 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'values': 0.26; '(see': 0.27; 'possibly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'finds': 0.29; 'speakers': 0.30; 'function': 0.30; 'error': 0.30; '(and': 0.32; 'problem.': 0.32; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'compare': 0.36; "didn't": 0.36; 'thank': 0.36; 'possible': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'wide': 0.62; 'times': 0.63; 'within': 0.64; 'here': 0.65; 'skip:m 50': 0.65 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 :content-type; bh=4HePMtwVeyFLj0KG8MrfHn7q5re8K/8uTNygFjlJfqs=; b=z5WhNbm0TgfwjDOd2kbgkDsS9DBYD5Y+zaaoJW8MTwgCLFzngpbSG8jacQKDzfEAV4 J9NovNK9M+VMgHqmbOhAiHKyysIdprrwZcFRDrBC3StVpb57mOOh8XPsOSpEHXZGJrB5 OUccw1J/H80lbeRP3v5tlrWw3g8VFmuM3jCBc5T9Ei0CD2Z/8AW4APFcYefbz5xKbBmf 0HFhI4T69hEr/gRL5Swa1Xi6aBUBn937yutQ+qmxJ7p0nfkA0jyn/D3MqEYThVpumUdw BzCY1Qy3+IcF2g68t7tggd9qJQIbHxuGDwgqQ1smWLTz1qg+FRGBH/umwozteRNA1kLb vSWg== MIME-Version: 1.0 In-Reply-To: <50C0D168.2010101@mrabarnett.plus.com> References: <50c01fe2$0$21853$c3e8da3$76491128@news.astraweb.com> <50C0D168.2010101@mrabarnett.plus.com> Date: Thu, 6 Dec 2012 18:31:26 +0100 Subject: Re: Confused compare function :) From: Anatoli Hristov To: python-list@python.org Content-Type: text/plain; charset=UTF-8 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354815089 news.xs4all.nl 6936 [2001:888:2000:d::a6]:51698 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34410 >> Here is the product in the CSV: >> MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide >> 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41;;;;;;;;; This one is still not found and it is in the CSV file - I just don't get it why ! >> if len(db_sku) != 0 and match: >> TotalSKUFound +=1 > TotalSKUFound is incremented if it finds a match. > > Can "db_sku in csv_sku" be true multiple times for a given value of > db_sku? (See above.) Is it possible that TotalSKUFound is incremented > multiple times for some values of csv_sku? Most of the SKU's are not doubled in the CSV, but what I will do is to create new function to compare each SKU so after it founds the SKU in the file it will return right away to the DB loop. >> if csv_new_price < db_price and csv_stock > 0: >> print db_sku, csv_price, db_price, >> csv_new_price >> Update_SQL(csv_new_price, db_sku) >> TotalUpdated += 1 >> found = True > It sets found to True if it updated. >> except IndexError: # I have a lot of index error in the >> CSV (empty fields) and the loop gives "index error" I don't care about them >> pass >> except ValueError: >> pass >> except TypeError: >> pass > > > Even after finding a match (and possibly updating), it continues > iterating though pricelist. Yes it will change after I create the new func.as I assume. >> except IndexError: > > if not found: WriteLog(db_sku, db_sku,) > > > Calling it 'found' is misleading, because it's True only if it updated. > If it found a match but didn't update, 'found' will still be False. > Using a loop within a loop like this could be the cause of your > problem. It's certainly not the most efficient way of doing it. I will keep you posted THANK YOU