我运行以下代码时出现错误:
为什么会这样?
#!/usr/bin/env python
from xml import sax
import sys
class MySaxHandler(sax.ContentHandler, object):
def startElement(self, name, attrs):
print(name, attrs)
if __name__ == '__main__':
sax.parse(sys.stdin, MySaxHandler)
以下是跟踪信息:
Traceback (most recent call last):
File "/tmp/a.py", line 13, in <module>
sax.parse(sys.stdin, MySaxHandler)
File "/usr/lib/python3.6/xml/sax/__init__.py", line 33, in parse
parser.parse(source)
File "/usr/lib/python3.6/xml/sax/expatreader.py", line 110, in parse
self._cont_handler.setDocumentLocator(ExpatLocator(self))
TypeError: setDocumentLocator() missing 1 required positional argument: 'locator'
为什么会这样?