ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved