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:
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
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://
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
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
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
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
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
> 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:
>
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
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
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
% (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
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
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
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
16 matches
Mail list logo