Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53305
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Neil Cerutti <neilc@norwich.edu> |
| Newsgroups | comp.lang.python |
| Subject | sax.handler.Contenthandler.__init__ |
| Date | 30 Aug 2013 17:20:16 GMT |
| Organization | Norwich University |
| Lines | 24 |
| Message-ID | <b8c2igFiupsU1@mid.individual.net> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net obpi+skXP8Ewn5qBkdsalwEPrvyNflJje4AZ4mE/1ObZ9egqZn |
| Cancel-Lock | sha1:uG4VUBJRdfnrOo1bBaHaJhM1yFk= |
| User-Agent | slrn/0.9.9p1/mm/ao (Win32) |
| Xref | csiph.com comp.lang.python:53305 |
Show key headers only | View raw
This code is from The Python Cookbook, 2nd edition, 12.2 Counting
Tags in a Document:
from xml.sax.handler import ContentHandler
import xml.sax
class countHandler(ContentHandler):
def __init__(self):
self.tags={}
def startElement(self, name, attr):
self.tags[name] = 1 + self.tags.get(name, 0)
Isn't overriding __init__ a risky thing to do? The docs don't
mention it as a method I should override, and also don't define
what's in there or if I'd need to call the base class __init__.
Moreover, startDocument is provided for parser setup.
As it happens, ContentHandler.__init__ isn't empty, so the above
code could fail if the parser isn't prepared for _locator to be
undefined.
Is the above code is an acceptable idiom?
--
Neil Cerutti
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
sax.handler.Contenthandler.__init__ Neil Cerutti <neilc@norwich.edu> - 2013-08-30 17:20 +0000 RE: sax.handler.Contenthandler.__init__ "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid> - 2013-08-30 17:35 +0000
csiph-web