[Tutor] Matching zipcode in address file

TGW galaxywatcher at gmail.com
Sun Apr 4 23:18:48 CEST 2010


I wrote a script that compares two text files (one zip code file, and  
one address file)  and tries to output records that match the  
zipcodes. Here is what I have so far:

#!/usr/bin/env python
# Find records that match zipcodes in zips.txt

def main():
     infile = open("/Users/tgw/NM_2010/NM_APR.txt", "r")
     outfile = open("zip_match_apr_2010.txt", "w")
     match_zips = open("zips.txt", "r")

     lines = [line for line in infile if line[149:154] in match_zips]  
# *** I think the problem is here ***

     outfile.write(''.join(lines))
     infile.close()
     outfile.close()
main()

I go the program functioning with
lines = [line for line in infile if line[149:154] not in match_zips]

But this matches records that do NOT match zipcodes. How do I get this  
running so that it matches zips?

Thanks


More information about the Tutor mailing list