当我实例化xml.etree.ElementTree.TreeBuilder
对象时,我看不到任何TreeBuilder
的私有属性。
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import xml.etree.ElementTree as etree
>>> etree.__file__
'C:\\Python34\\Lib\\xml\\etree\\ElementTree.py'
>>> b = etree.TreeBuilder()
>>> b._data
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'xml.etree.ElementTree.TreeBuilder' object has no attribute '_data'
>>>
即使_data
应该在那里(摘自C:\Python34\Lib\xml\etree\ElementTree.py
,第1384行):
def __init__(self, element_factory=None):
self._data = [] # data collector
self._elem = [] # element stack
self._last = None # last element
self._tail = None # true if we're after an end tag
if element_factory is None:
element_factory = Element
self._factory = element_factory
我希望子类TreeBuilder
添加对XML注释元素的支持,但需要获取其中一个私有属性来附加注释元素。