[Tutor] Omitting lines matching a list of strings from a file
Reed O'Brien
reed at reedobrien.com
Thu Feb 25 08:17:53 CET 2010
> def main():
> infile = open("list.txt", "r")
> for line in infile:
> state = line[146:148]
> omit_states = ['KS', 'KY', 'MA', 'ND', 'NE', 'NJ', 'PR',
> 'RI', 'SD', 'VI', 'VT', 'WI']
> for n in omit_states:
> if state != n:
> print line
> infile.close()
> main()
If state not in omit_states:
process_line(line)
~ro
--
Sent from a mobile device.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100225/91b33254/attachment.html>
More information about the Tutor
mailing list