[Tutor] print out lines that start with a word

2005-02-08 Thread Ron Nixon
Can anyone tell me what I've done wrong in this script. I'm trying to get only the lines that start with "This" for a text file. Here's what I wrote: >>> import re >>> f = open('c:/lines.txt').readlines() >>> for line in f: match = re.search('^This',f) if line == match:

[Tutor] error message

2005-02-13 Thread Ron Nixon
I'm dping something very simple in RE. Lets say I'm trying to match an American Phone number I write the code this way and try to match it: import re string = 'My phone is 410-995-1155' pattern = r'\d{3}-\d{3}-\d{4}' re.match(pattern,string).group() but I get this error message Traceback (most r

[Tutor] writing list to new file

2005-02-13 Thread Ron Nixon
How would I save a list to a new file for example: If line.startswith('XXX'): save list to new file But I get errors saying only stings can be saved this way. __ Do you Yahoo!? Meet the all-new My Yahoo! - Try it today! http://

[Tutor] Value Error message

2005-02-13 Thread Ron Nixon
Trying to scrape some headlines off a newspaper with this code: import urllib, re pattern = re.compile("""(.*)""", re.DOTALL) page = urllib.urlopen("http://www.startribune.com";).read() for (headline, code, description) in pattern.findall(page): print (headline, code, description) I'm gett

[Tutor] Value Error solved. Another question

2005-02-13 Thread Ron Nixon
Ignore my first posting. Here's what I'm trying to do. I want to extract headlines from a newspaper's website using this code. It works, but I want to match the second group in (.*) and print that out. Sugguestions import urllib, re pattern = re.compile("""(.*)""", re.DOTALL) page = urllib.urlope

[Tutor] count words

2005-02-15 Thread Ron Nixon
I know that you can do this to get a count of home many times a word appears in a file f = open('text.txt').read() print f.count('word') Other than using a several print statments to look for seperate words like this, is there a way to do it so that I get a individual count of each word: word1

RE: [Tutor] count words

2005-02-15 Thread Ron Nixon
t;>> counts = {} > >>> for word in x.split(): > ... counts[word] = x.count(word) > ... > >>> counts > {'foo': 2, 'bar': 1, 'asdf': 1} > ### > The dictionary takes care of duplicates. If you are > using a really big fi

[Tutor] RE help

2005-02-15 Thread Ron Nixon
Trying to scrape a newspaper site for articles using this code whic ws done with help from the list: import urllib, re pattern = re.compile("""(.*).""", re.DOTALL) page =urllib.urlopen("http://www.startribune.com";).read() for headline, body in pattern.findall(page): print body It should g

Re: [Tutor] RE help

2005-02-15 Thread Ron Nixon
> pattern = re.compile(""" href="/(.*?)">(.*?)\.""", re.DOTALL) > > Kent > > Ron Nixon wrote: > > Trying to scrape a newspaper site for articles > using > > this code whic ws done with help from the list: >

[Tutor] Better Search and replace method

2005-03-02 Thread Ron Nixon
I'm trying to figure out a better solution to do multiple search and replaces in a text file without having to type: import re s = open('filename') re.sub('vaule1','value2',s) re.sub('vaule3','value4',s) etc I've tried putting all the vaules in a list and doing the replace, but came up short. An

[Tutor] re help

2005-03-13 Thread Ron Nixon
The following program takes text data like this: Jimi Hendrix 2100 South Ave Seattle, WA 55408 and changes it to this Jimi Hendrix, 2100 South Ave,Seattle,WA,55488 and writes it to a file. The problem I'm running into is that it only writes this first address to a file and there are several oth

[Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Ron Nixon
Thanks to all who replied to my post earlier on re's. I'm still preplexed by why re.search and re.match works in the code below, but not re.findall. re.findall is suppose to return all non-voerlapping occurances of the pattern that matches in this example, but it returns errors. Looking through th

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Ron Nixon
% (name, address, citystate,zipcd)) o.close() print("%s,%s,%s,%s\n" % (name, address, citystate,zipcd)) --- Kent Johnson <[EMAIL PROTECTED]> wrote: > Ron Nixon wrote: > > Thanks to all who replied to my post earlier on > re's. > > I'm still preplexed by why

[Tutor] CPAN for python

2005-06-06 Thread Ron Nixon
Is there a site like Perl's CPAN for Python? I've seen the stuff at ActiveState. Anything else? Ron Nixon __ Discover Yahoo! Have fun online with music videos, cool games, IM and more. Check it out! http://discover.yahoo.com/o

[Tutor] python mechanize examples

2006-02-16 Thread Ron Nixon
Anyone have or know where I can find working examples of python's mechanize modules. Try to reverse engineer a script to see how it works. Ron Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.___ Tutor

[Tutor] urlretrieve

2007-01-12 Thread Ron Nixon
Is there a way to get the urlretrive module to grab multiple files similar to wget? Ron Nixon Expecting? Get great news right away with email Auto-Check. Try the Yahoo! Mail Beta. http