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 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

[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', '

[Tutor] Python workspace - IDE and version control

2010-01-18 Thread galaxywatcher
I want to share a couple of insights that I had getting started with Python that I did not come across in the literature all that often. I am discovering that there are two primary supporting tools needed in order to create an efficient and productive Python programming workspace: IDE and V

Re: [Tutor] Expanding a Python script to include a zcat and awk pre-process

2010-01-09 Thread galaxywatcher
I finally got it working! I would do a victory lap around my apartment building if I wasn't recovering from a broken ankle. Excuse my excitement, but this simple script marks a new level of Python proficiency for me. Thanks to Kent, Bob, Denis, and others who pointed me in the right directi

Re: [Tutor] Expanding a Python script to include a zcat and awk pre-process

2010-01-09 Thread galaxywatcher
After many more hours of reading and testing, I am still struggling to finish this simple script, which bear in mind, I already got my desired results by preprocessing with an awk one-liner. I am opening a zipped file properly, so I did make some progress, but simply assigning num1 and num2

[Tutor] Expanding a Python script to include a zcat and awk pre-process

2010-01-07 Thread galaxywatcher
I wrote a simple Python script to process a text file, but I had to run a shell one liner to get the text file primed for the script. I would much rather have the Python script handle the whole task without any pre-processing at all. I will show 1) a small sample of the text file, 2) my scr

[Tutor] Greetings Pythonistas

2010-01-07 Thread galaxywatcher
This is my first post to the Python tutor list and I just wanted to introduce myself and give a little background on my skill level prior to asking for Python advice and programming tips. I am relatively new to Python, but I have been dabbling with unix shell scripting for at least 10 years