I'd suggest reading the data from the match_zips into a list, and if the format isn't correct, doing some post-processing on it. But there's no way to advise on that since we weren't given the format of either file.

zipdata = match_zips.readlines()
Then you can do an      if XXX in zipdata with assurance.

Here is a simplified version of the program:
#!/usr/bin/env python

def main():
     infile = open("filex")
     outfile = open("results_testx", "w")
     zips = open("zippys")
     match_zips = zips.readlines()
     results = [line for line in infile if line[0:2] in match_zips]
     outfile.write(''.join(results))

     zips.close()
     infile.close()
     outfile.close()
main()

filex:
112332424
23423423423
34523423423
456234234234
234234234234
5672342342
67824242

zippys:
567
678
555

I want to output the lines in filex that match the the first 3 chars of zippys.

output:
5672342342
67824242
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to