Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-28 Thread galaxywatcher
One formatting detail: there is a blank line after each line printed, how do I ged rid of the extra blank lines? lines = [line.strip() for line in infile if line[146:148] not in omit_states] print '\n'.join(lines) This approach stripped leading blank spaces introducing errors into my fi

Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-25 Thread Alan Gauld
"Christian Witts" wrote lines = [line for line in infile if line[146:148] not in omit_states] print ''.join(lines) Just remember that doing a list comprehension like that on a large file will drastically reduce the speed of your application as well as introduce memory bloat. Given he was

Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-25 Thread Christian Witts
galaxywatc...@gmail.com wrote: But I would do this with a list comprehension or generator expression (depending on your Python version): lines = [line for line in infile if line[146:148] not in omit_states] print '\n'.join(lines) That's very helpful. Thanks. One formatting detail: there is a

Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-25 Thread galaxywatcher
But I would do this with a list comprehension or generator expression (depending on your Python version): lines = [line for line in infile if line[146:148] not in omit_states] print '\n'.join(lines) That's very helpful. Thanks. One formatting detail: there is a blank line after each line pri

Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-25 Thread Alan Gauld
wrote I am trying to output a list of addresses that do not match a list of State abbreviations. What I have so far is: def main(): infile = open("list.txt", "r") for line in infile: state = line[146:148] omit_states = ['KS', 'KY', 'MA', 'ND', 'NE', 'NJ', 'PR', 'R

Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-24 Thread Reed O'Brien
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() ma

Re: [Tutor] Omitting lines matching a list of strings from a file

2010-02-24 Thread Christian Witts
galaxywatc...@gmail.com wrote: I am trying to output a list of addresses that do not match a list of State abbreviations. What I have so far is: def main(): infile = open("list.txt", "r") for line in infile: state = line[146:148] omit_states = ['KS', 'KY', 'MA', 'ND', 'N

[Tutor] Omitting lines matching a list of strings from a file

2010-02-24 Thread galaxywatcher
I am trying to output a list of addresses that do not match a list of State abbreviations. What I have so far is: 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', '