Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'modify': 0.05; '%s"': 0.07; '__name__': 0.07; 'completeness': 0.07; "'''": 0.09; 'received:155': 0.09; 'rows': 0.09; 'script,': 0.09; 'subject:files': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '"rb"': 0.16; "'__main__':": 0.16; 'between.': 0.16; 'csv': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'row': 0.16; 'securities,': 0.16; 'skip:n 50': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'writer': 0.16; 'wrote:': 0.17; 'creates': 0.18; 'causing': 0.20; 'bit': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'insert': 0.23; 'specified': 0.23; 'to:2**1': 0.23; 'received:169.254': 0.24; 'script': 0.24; 'pass': 0.25; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wonder': 0.27; 'accuracy': 0.27; 'first.': 0.27; 'subject:list': 0.28; 'received:169': 0.29; "i'm": 0.29; 'mode': 0.30; 'writes': 0.30; 'figure': 0.30; 'file': 0.32; 'addresses': 0.32; 'print': 0.32; 'says': 0.33; 'problem': 0.33; "can't": 0.34; 'text': 0.34; 'list': 0.35; 'open': 0.35; 'but': 0.36; 'wanted': 0.36; 'compare': 0.36; 'too': 0.36; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'instead': 0.39; 'hello,': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'think': 0.40; 'range': 0.60; 'first': 0.61; 'strange': 0.62; 'skip:n 10': 0.63; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'phone': 0.68; 'tel': 0.75; 'sale': 0.76; 'phones:': 0.84; 'received:169.254.8': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sf2.jpmchase.com qATNJIYf021001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1354231158; bh=BbIxfO4BIll5YM7sD67KkfO2wTLU26tBdtXSmK4jx6Q=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=AFsRv1UzUN9/KPUeTHG06ZqMZ+gkrhGDV8vyh0WuZzoD/bC3cfZb9czCa+3fO2l3Y k+P8HY8vqUYe0t8NPw0g2gePDTNXxTL7YDPTtwowr7rRlPssrLD0JRGnTBz4zdniUs ftuyidGUiu4yNqZD/su8rVdMoMi3UmjLTY5N9DBE= From: "Prasad, Ramit" To: Anatoli Hristov , Neil Cerutti Subject: RE: Compare list entry from csv files Thread-Topic: Compare list entry from csv files Thread-Index: AQHNzN+kXq9f0aqd0kiHIQxc9YkzCZgA8O8AgACCkQA= Date: Thu, 29 Nov 2012 23:13:25 +0000 References: <50B3E865.9070700@davea.name> <50B43246.2010902@davea.name> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354232564 news.xs4all.nl 6906 [2001:888:2000:d::a6]:38996 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34082 Anatoli Hristov wrote:=0D=0A> Hello,=0D=0A> =0D=0A> Tried to document a lit= tle bit the script, but I'm not that good in that too :)=0D=0A> =0D=0A> The= only problem I have is that I cant compare other field than the=0D=0A> fir= st one in=0D=0A> for ex_phone in phones:=0D=0A> telstr =3D ex_phone= [0]=2Elower()=0D=0A> When I use telstr =3D ex_phone[0]=2Elower() it says ou= t of range and the=0D=0A> strange think is that the range is 6 I can't figu= re that out=2E So when=0D=0A> I edit the csv I modify the look of the file = and then I start the=0D=0A> script and it works, but I wanted to use more t= han one condition and I=0D=0A> can't :(=0D=0A> =0D=0A> =0D=0A=0D=0ACan you = print ex_phone first=2E You are opening the files in text mode=0D=0Aso I wo= nder if the line endings are causing you to read and extra=0D=0A"line" in b= etween=2E Can you try reading the csv as "rb" instead of =0D=0A"rt"?=0D=0A= =0D=0A> =0D=0A> =0D=0A> import csv=0D=0A> =0D=0A> # Open the file with the = names and addresses=0D=0A> origf =3D open('c:/Working/vpharma=2Ecsv', 'rt')= =0D=0A> # Open the file with the phone numbers=0D=0A> secfile =3D open('c:= /Working/navori=2Ecsv', 'rt')=0D=0A> =0D=0A> # Creates the empty list with = the names=0D=0A> namelist =3D []=0D=0A> # Creates the empty list with the p= hone numbers=0D=0A> PHONELIST =3D []=0D=0A> =0D=0A> =0D=0A> # Reads the fil= e with the names=0D=0A> # Format "Name","Phone"=0D=0A> names =3D csv=2Eread= er(origf, delimiter=3D';')=0D=0A> =0D=0A> # Reads the file with the phone n= umbers=0D=0A> # Format "First name","Lastname","Address","City","Country","= Phone"=0D=0A> phones =3D csv=2Ereader(secfile, delimiter=3D';')=0D=0A> =0D= =0A> # Creates a list with phone numbers=0D=0A> #for tel in phones:=0D=0A> = # PHONELIST=2Eappend(tel)=0D=0A> =0D=0A> =0D=0A> def finder(Compare_Name= ,rows):=0D=0A> '''=0D=0A> Compare the names from the namelist with = the names from the phonelist=2E=0D=0A> If the name match - then the pho= ne number is added to the specified field=0D=0A> '''=0D=0A> for ex_= phone in phones:=0D=0A> telstr =3D ex_phone[0]=2Elower()=0D=0A> = print telstr=0D=0A> if telstr=2Efind(Compare_Name) >=3D 0:=0D= =0A> print "\nName found: %s" % Compare_Name=0D=0A> = namelist[rows][-1] =3D ex_phone[-1]=2Elower()=0D=0A> else:=0D=0A> = print "Not found %s" % Compare_Name=0D=0A> pass=0D= =0A> return=0D=0A> =0D=0A> def name_find():=0D=0A> rows =3D 0=0D=0A= > for row in names:=0D=0A> namelist=2Eappend(row)=0D=0A> = Compare_Name =3D row[1]=2Elower()=0D=0A> finder(Compare_Name,rows= )=0D=0A> rows =3D rows+1=0D=0A> =0D=0A> if __name__ =3D=3D '__main_= _':=0D=0A> name_find()=0D=0A> =0D=0A> # Writes the list to a file=0D=0A= > wfile =3D open('c:/Working/ttest=2Ecsv', "wb")=0D=0A> writer =3D csv=2Ew= riter(wfile, delimiter=3D';')=0D=0A> for insert in namelist:=0D=0A> wri= ter=2Ewriterow(insert)=0D=0A> wfile=2Eclose()=0D=0A=0D=0A=0D=0A~Ramit=0D=0A= =0D=0A=0D=0AThis email is confidential and subject to important disclaimers= and=0D=0Aconditions including on offers for the purchase or sale of=0D=0As= ecurities, accuracy and completeness of information, viruses,=0D=0Aconfiden= tiality, legal privilege, and legal entity disclaimers,=0D=0Aavailable at h= ttp://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E