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


Groups > comp.lang.python > #64465

Re: Separate Address number and name

Newsgroups comp.lang.python
Date 2014-01-21 16:06 -0800
References <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com>
Message-ID <a218f6ef-37c1-4eaf-a127-5ea4846cb332@googlegroups.com> (permalink)
Subject Re: Separate Address number and name
From Shane Konings <shane.konings@gmail.com>

Show all headers | View raw


inHandler = open(inFile, 'r')
outHandler = open(outFile, 'w')
outHandler.write('ID\tAddress\tStreetNum&Name\tSufType\tDir\tCity\tProvince\tPostalCode\n')
for line in inHandler:
    str = line.replace('FarmID\tAddress','')
    outHandler.write(str[0:-1])
    str = str.replace(', ON', '\t ON\t')
    str = str.replace(' Rd,', '\t Rd\t \t')
    str = str.replace(' Rd ', '\t Rd\t \t')
    str = str.replace(' St,', '\t St\t \t')
    str = str.replace(' St ', '\t St\t \t')
    str = str.replace(' Ave', '\t Ave\t \t')
    str = str.replace(' Pky', '\t Pky\t \t')
    str = str.replace(' Lane, ', '\t Lane\t \t')
    str = str.replace(', Lane, , Rd,', ' Lane\t Rd\t')
    str = str.replace(' Dr', '\t Dr\t \t')
    str = str.replace(' Sq', '\t Sq\t \t')
    str = str.replace(' Pl', '\t Pl\t \t')
    str = str.replace('\t \tN,', '\tN\t')
    str = str.replace('\t \t N,', '\tN\t')
    str = str.replace(' , North ', ' N\t')
    str = str.replace(' ,S ', ' S\t')
    str = str.replace(' , South ', ' S\t')
    str = str.replace('\t \tE,', '\tE\t')
    str = str.replace(' , East ', ' E\t')
    str = str.replace('\t \tW,', '\tW\t')
    str = str.replace('\t \t West', '\tW\t')
    str = str.replace(',.', '.')
    str = str.replace(',', '\t')
    str = str.replace(',,', '\t')
    str = str.replace(', Service', ' Service')
    str = str.replace('\t \t\t', '\t\t')
    outHandler.write(str[1:])
inHandler.close()
outHandler.close()


That is the code i currently have.

The following is a sample of the data. There are hundreds of lines that need to have an automated process of splitting the strings into headings to be imported into excel with theses headings 

ID  Address  StreetNum  StreetName  SufType  Dir   City  Province  PostalCode


1	1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0
2	4260 Mountainview Rd, Lincoln, ON L0R 1B2
3	25 Hunter Rd, Grimsby, E, ON L3M 4A3
4	1091 Hutchinson Rd, Haldimand, ON N0A 1K0
5	5172 Green Lane Rd, Lincoln, ON L0R 1B3
6	500 Glenridge Ave, East, St. Catharines, ON L2S 3A1
7	471 Foss Rd, Pelham, ON L0S 1C0
8	758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0
9	3836 Main St, North, Lincoln, ON L0R 1S0
10	1025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0

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


Thread

Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 15:49 -0800
  Re: Separate Address number and name Anders Wegge Keller <wegge@wegge.dk> - 2014-01-22 00:55 +0100
    Re: Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 16:01 -0800
  Re: Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 16:06 -0800
    Re: Separate Address number and name Anders Wegge Keller <wegge@wegge.dk> - 2014-01-22 02:04 +0100
    Re: Separate Address number and name Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-22 10:08 +0000
    Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-22 17:35 +0000
      Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-23 18:11 +0000
  Re: Separate Address number and name Asaf Las <roegltd@gmail.com> - 2014-01-21 16:08 -0800
  Re: Separate Address number and name Ben Finney <ben+python@benfinney.id.au> - 2014-01-22 11:08 +1100
  Re: Separate Address number and name John Gordon <gordon@panix.com> - 2014-01-22 02:46 +0000
    Re: Separate Address number and name Tim Chase <python.list@tim.thechases.com> - 2014-01-21 21:03 -0600
  Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-22 15:40 +0000

csiph-web