there's no DefaultHandler
a64bs4$1oo$1@newsreader.mailgate.org
eugene1977 at hotmail.com
Tue Jul 16 12:41:18 EDT 2002
hi. i'm trying to run my first python program
i'm using python 2.2
[eugene at eugene python]$ python firstxml.py
Traceback (most recent call last):
File "firstxml.py", line 6, in ?
class FindIssue(xml.sax.DefaultHandler):
AttributeError: 'module' object has no attribute 'DefaultHandler'
#!/usr/bin/python
from xml.sax import saxutils
import xml
class FindIssue(xml.sax.DefaultHandler):
def __init__(self, title, number):
self.search_title, self.search_number = title, number
def startElement(self, name, attrs):
# If it's not a comic element, ignore it
if name != 'comic': return
# Look for the title and number attributes (see text)
title = attrs.get('title', None)
number = attrs.get('number', None)
if (title == self.search_title and
number == self.search_number):
print title, '#' + str(number), 'found'
from xml.sax import make_parser
from xml.sax.handler import feature_namespaces
if __name__ == '__main__':
# Create a parser
parser = make_parser()
# Tell the parser we are not interested in XML namespaces
parser.setFeature(feature_namespaces, 0)
# Create the handler
dh = FindIssue('Sandman', '62')
# Tell the parser to use our handler
parser.setContentHandler(dh)
# Parse the input
parser.parse("samplexml")
if i change DefaultHandler to handler
i get this error
[eugene at eugene python]$ python firstxml.py
Traceback (most recent call last):
File "firstxml.py", line 35, in ?
dh = FindIssue('Sandman', '62')
TypeError: 'module' object is not callable
thank you
More information about the Python-list
mailing list