Re: Passing data out of a Sax parser
by John J. Lee other posts by this author
Sep 21 2003 9:51PM messages near this date
Cincinnati PUG
|
python-dev Summary for 2003-09-01 through 2003-09-15
"Andrew Dalke" <adalke@[...].com> writes:
> Tim Rowe:
> > b. Add a parameter to the handler's __init__ method, that takes some
> > sort of mutable object, and put the answer into that object.
>
> Either that or have startDocument create the mutable object, as
>
> class MyHandler(xml.sax.handlers.ContentHandler):
> def startDocument(self):
> self.count = 0
> def startElement(self, name, attrs):
> if name == "spam":
> self.count += 1
>
> parser = xml.sax.make_parser()
> h = MyHandler()
> parser.setContentHandler(h)
> h.parse(input)
> print h.count
Works, but integers aren't mutable.
John
--
http://mail.python.org/mailman/listinfo/python-list
|