为什么我的TreeBuilder对象不包含TreeBuilder的私有属性?

时间:2015-03-03 14:10:57

标签: python elementtree

当我实例化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注释元素的支持,但需要获取其中一个私有属性来附加注释元素。

0 个答案:

没有答案