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 -- https://mail.python.org/mailman/listinfo/python-list