formatter output to list

John Hunter jdhunter at nitace.bsd.uchicago.edu
Tue May 21 12:16:20 EDT 2002


I have a urlopen file object that I am passing to formatter DumbWriter
to strip the html

def html2txt( fh ):
    oh = open('temp.out', 'w')
    p = htmllib.HTMLParser(
        formatter.AbstractFormatter(formatter.DumbWriter(oh)))
    p.feed(fh.read())

I am then doing some post processing on the file 'temp.out'.

Rather than communicating via the file 'temp.out', I want the
DumbWriter to return a list of lines.  I see two solutions: derive a
new class from AbstractWriter or pass a list like object which
implements the necessary file object methods to html2txt and have that
func return the modified object.

Suggestions?
Thanks,
John Hunter



More information about the Python-list mailing list