Re: [Tutor] Tutor Digest, Vol 81, Issue 3

2010-11-01 Thread TGW
rgr. On Nov 1, 2010, at 5:21 PM, tutor-requ...@python.org wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or bo

Re: [Tutor] modify csv textfile

2010-08-07 Thread TGW
> You can test if one item in your list begins with example like: > ' example125 oo3 3456'.lstrip()[:7].lower() == 'example' I think I need to use regex here. Perhaps you will agree. Input file: 1119|Avail|53|Potato Chips 1234|Avail|53|Potato Chips and salse 1399|Avail|53|potato chips 1445|Avail|

[Tutor] modify csv textfile

2010-08-06 Thread TGW
I have a pipe delimited text file with 5 columns which looks like this: 12345|some text|some more text|example125 oo3 3456|example32423 11223|more text|and more|example/73d 77665|example455667 12677|text|more|anotherexample 123|anotherexample45 What I want to output is: 12345|some text|some more t

Re: [Tutor] Matching zipcode in address file

2010-04-05 Thread TGW
I got it. I was comparing '345' to '345\n' Adding the '\n' to the slice did indeed do the trick. #!/usr/bin/env python import string def main(): infile = open("filex") outfile = open("results_testx", "w") zips = open("zippys", "r") match_zips = zips.readlines() lines =

Re: [Tutor] Matching zipcode in address file

2010-04-05 Thread TGW
OK - you handled the problem regarding reading to end-of-file. Yes it takes a lot longer, because now you are actually iterating through match_zips for each line. How large are these files? Consider creating a set from match_zips. As lists get longer, set membership test become faster than list

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
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

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
ank. Any suggestions? #!/usr/bin/env python # Find records that match zipcodes in zips.txt import os import sys def main(): infile = open("/Users/tgw/NM_2010/NM_APR.txt", "r") outfile = open("zip_match_apr_2010.txt", "w") zips = open("zips.txt&quo

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
Sorry - my mistake - try: infile = open("filex") match_zips = open("zippys") result = [line for line in infile if line in match_zips] print result okThanks...This should do it: #!/usr/bin/env python infile = open("filex") zips = open("zippys") match_zips = zips.readlines() results = [lin

[Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
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