Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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.078 X-Spam-Evidence: '*H*': 0.84; '*S*': 0.00; 'else:': 0.03; 'paths': 0.07; 'cc:addr:python-list': 0.11; "'w')": 0.16; 'skip:o 100': 0.16; 'file,': 0.19; 'seems': 0.21; '8bit%:5': 0.22; 'cc:addr:python.org': 0.22; 'directory.': 0.24; 'rid': 0.24; 'skip:l 30': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; "skip:' 10": 0.31; 'about.': 0.31; 'work:': 0.31; 'stuff': 0.32; 'url:python': 0.33; 'skip:& 30': 0.33; 'actual': 0.34; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'skip:o 20': 0.38; 'skip:& 10': 0.38; '8bit%:4': 0.38; 'skip:& 20': 0.39; 'help,': 0.39; 'changed': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; 'skip:l 50': 0.60; 'skip:o 30': 0.61; 'school': 0.64; 'talking': 0.65; 'to:addr:gmail.com': 0.65; 'skip:r 30': 0.69; 'postal': 0.74; 'subject:Unwanted': 0.84; 'taught': 0.96 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=MV16NReLgD9HzSbuYOTKpNDGUjpmOfP7l685bn+Ql2E=; b=HKrrES8KRAWYrVGKY/QutMi25cAUpao6i4qHPuNcphlWMhnC9vfOk9aXjxHqIUeiMZ AGhbZSVAS7tpEAGz+N13ztb3c+aEt+Pu0fVRAOGLBxAcSuaAoQ/c9mEIsQTz2BLHMH9s PFdu6mD4Dn5Di7y0T8qftTXRmGq8tFRif1itOtgkh7d75aM2KkPKLvq9tOvrDKyqxjrS IRkgJZgVhGLc7qDYwLrA8aPX2KMq/aHSIKwTWlTZV6UK5ZdHxAujT0RqVFDl1UT8ctGQ ywsxakj5ISaPPrQVHn8Uw7oZwy24hyWCHGW6p+4h9w1SpeejpziCd6jSklalmA37q4XQ 8VRA== MIME-Version: 1.0 X-Received: by 10.42.122.146 with SMTP id n18mr2696642icr.41.1390788035844; Sun, 26 Jan 2014 18:00:35 -0800 (PST) In-Reply-To: <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> Date: Sun, 26 Jan 2014 19:00:35 -0700 Subject: Re: Unwanted Spaces and Iterative Loop From: Jason Friedman To: matt.s.marotta@gmail.com Content-Type: multipart/alternative; boundary=20cf3011d9b9d5a26d04f0ea1200 Cc: python-list 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: 117 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390788044 news.xs4all.nl 2912 [2001:888:2000:d::a6]:49600 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64817 --20cf3011d9b9d5a26d04f0ea1200 Content-Type: text/plain; charset=UTF-8 > > I`m not reading and writing to the same file, I just changed the actual > paths to directory. > > This is for a school assignment, and we haven`t been taught any of the > stuff you`re talking about. Although I appreciate your help, everything > needs to stay as is and I just need to create the loop to get rid of the > farmID from the end of the postal codes. > -- > https://mail.python.org/mailman/listinfo/python-list > If you are allowed to use if/then this seems to work: inFile = "data" outFile = "processed" inHandler = open(inFile, 'r') outHandler = open(outFile, 'w') for line in inHandler: if line.startswith("FarmID"): outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode\n") else: line = line.replace(" ","\t", 1) line = line.replace(" Rd,","\tRd\t\t") line = line.replace(" Rd","\tRd\t") line = line.replace("Ave,","\tAve\t\t") line = line.replace("Ave ","\tAve\t\t") line = line.replace("St ","\tSt\t\t") line = line.replace("St,","\tSt\t\t") line = line.replace("Dr,","\tDr\t\t") line = line.replace("Lane,","\tLane\t\t") line = line.replace("Pky,","\tPky\t\t") line = line.replace(" Sq,","\tSq\t\t") line = line.replace(" Pl,","\tPl\t\t") line = line.replace("\tE,","E\t") line = line.replace("\tN,","N\t") line = line.replace("\tS,","S\t") line = line.replace("\tW,","W\t") line = line.replace(",","\t") line = line.replace(" ON","ON\t") outHandler.write(line) inHandler.close() --20cf3011d9b9d5a26d04f0ea1200 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I`m not reading and writing to the same file, I just changed the actual pat= hs to directory.

This is for a school assignment, and we haven`t been taught any of the stuf= f you`re talking about. =C2=A0Although I appreciate your help, everything n= eeds to stay as is and I just need to create the loop to get rid of the far= mID from the end of the postal codes.
--
https://mail.python.org/mailman/listinfo/python-list

If yo= u are allowed to use if/then this seems to work:

inFil= e =3D "data"
outFile =3D "processed"
inHandler =3D open(inFile, 'r')
outHandler =3D open(outFile, 'w')
for line in inHandler:
=C2=A0 =C2=A0 if lin= e.startswith("FarmID"):
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 outHandler.write("FarmID\tAddress\tStreetNum\tStr= eetName\tSufType\tDir\tCity\tProvince\tPostalCode\n")
=C2=A0 =C2=A0 else:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace(" ","\= t", 1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 lin= e =3D line.replace(" Rd,","\tRd\t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replac= e(" Rd","\tRd\t")
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace("Ave,","\tAve= \t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 lin= e =3D line.replace("Ave ","\tAve\t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replac= e("St ","\tSt\t\t")
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace("St,","\tSt\t= \t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line = =3D line.replace("Dr,","\tDr\t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replac= e("Lane,","\tLane\t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace("Pky,","\= tPky\t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace(" Sq,","\t= Sq\t\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 l= ine =3D line.replace(" Pl,","\tPl\t\t")

=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace("\tE,","E\= t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line = =3D line.replace("\tN,","N\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replace("\tS,",= "S\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.replac= e("\tW,","W\t")
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 line =3D line.replace(",","\t")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 line =3D line.rep= lace(" ON","ON\t")

=C2=A0 =C2= =A0 =C2=A0 =C2=A0 outHandler.write(line)
in= Handler.close()
--20cf3011d9b9d5a26d04f0ea1200--