Splitting on a word

Robert Kern rkern at ucsd.edu
Wed Jul 13 09:34:35 EDT 2005


qwweeeit at yahoo.it wrote:
> Hi all,
> I am writing a script to visualize (and print)
> the web references hidden in the html files as:
> '<a href="web reference"> underlined reference</a>'
> Optimizing my code, I found that an essential step is:
> splitting on a word (in this case 'href').
> 
> I am asking if there is some alternative (more pythonic...):

For *this* particular task, certainly. It begins with

   import BeautifulSoup

The rest is left as a (brief) exercise for the reader.  :-)

As for the more general task of splitting strings using regular 
expressions, see re.split().

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list