我正在使用lxml.objectify在我的应用程序中为Python和自定义元素定义了一些元素。当我向自定义元素类添加属性时,会调用getter而不是setter。将调用元素的子元素的名称添加到元素的setter中,而不是使用新的元素名称。在
我假设我的getter定义正确地覆盖了ObjectifiedElement的__getattr__
方法,但是由于某些原因,ObjectifiedElement的__setattr__
方法优先于我的setter。在
怎样才能让它执行我的setter呢?在
class CT_TextParagraph(objectify.ObjectifiedElement):
"""<a:p> custom element class"""
def _get_algn(self):
"""
Value of algn attribute on <a:pPr> child element
"""
if not hasattr(self, 'pPr'):
return None
return self.pPr.get('algn')
def _set_algn(self, value):
"""
Set value of algn attribute on <a:pPr> child element
"""
raise AssertionError('in _set_algn()')
# if not hasattr(self, 'pPr'):
# pPr = _Element('a:pPr')
# self.insert(0, pPr)
self.pPr.set('algn', value)
#: Paragraph horizontal alignment value, like ``TAT.CENTER``
algn = property(_get_algn, _set_algn)
目前没有回答
相关问题 更多 >
编程相关推荐