Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64817

Re: Unwanted Spaces and Iterative Loop

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 <jsf80238@gmail.com>
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 <jsf80238@gmail.com>
To matt.s.marotta@gmail.com
Content-Type multipart/alternative; boundary=20cf3011d9b9d5a26d04f0ea1200
Cc python-list <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6015.1390788044.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

>
> 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()

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unwanted Spaces and Iterative Loop matt.s.marotta@gmail.com - 2014-01-26 13:46 -0800
  Re: Unwanted Spaces and Iterative Loop Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-26 22:20 +0000
  Re: Unwanted Spaces and Iterative Loop MRAB <python@mrabarnett.plus.com> - 2014-01-26 23:28 +0000
  Re: Unwanted Spaces and Iterative Loop Jason Friedman <jsf80238@gmail.com> - 2014-01-26 16:44 -0700
    Re: Unwanted Spaces and Iterative Loop matt.s.marotta@gmail.com - 2014-01-26 15:56 -0800
  Re: Unwanted Spaces and Iterative Loop Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 00:40 +0000
    Re: Unwanted Spaces and Iterative Loop matt.s.marotta@gmail.com - 2014-01-26 17:15 -0800
      Re: Unwanted Spaces and Iterative Loop Chris Angelico <rosuav@gmail.com> - 2014-01-27 12:56 +1100
        Re: Unwanted Spaces and Iterative Loop matt.s.marotta@gmail.com - 2014-01-26 17:58 -0800
          Re: Unwanted Spaces and Iterative Loop Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 13:32 +0000
      Re: Unwanted Spaces and Iterative Loop Jason Friedman <jsf80238@gmail.com> - 2014-01-26 19:00 -0700
        Re: Unwanted Spaces and Iterative Loop matt.s.marotta@gmail.com - 2014-01-26 19:07 -0800

csiph-web