On May 19, 8:09 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > On May 19, 4:54 am, [EMAIL PROTECTED] wrote:> Hello, > > <snip code example scraping a QOTD fromwww.mcgyver.com> > > > > > print out > > ************** > > Since you have no control over spacing and line breaks in the input, > you can reformat using the textwrap module. First replace all "\n"s > with " ", then use re.sub to replace multiple spaces with a single > space, then call textwrap.fill to reformat the line into lines up to > 'n' characters long (I chose 50 in the sample below, but you can > choose any line length you like). > > out = match.findall(html) > out = out[0].replace("\n"," ") > out = re.sub("\s+"," ",out) > > print textwrap.fill(out,50) > > -- Paul
One last try - .replace("\n"," ") is unnecessary, textwrap.fill takes care of removing extra newlines already. out = match.findall(html) out = out[0] out = re.sub("\s+"," ",out) print textwrap.fill(out,50) -- Paul -- http://mail.python.org/mailman/listinfo/python-list