[英]Python ElementTree XML Parsing: element objects's bool value is strange
我的xml
文件是這樣的:
<aiml>
<category>
<pattern>*test*</pattern>
<template><srai>test</srai></template>
</category>
</aiml>
問題是當我檢查srai
的bool值時,它返回false
(Pdb) not srai_tag
True
(Pdb) srai_tag
<Element 'srai' at 0x10e08fea8>
(Pdb) not template
False
(Pdb) template
<Element 'template' at 0x10e08fe58>
我的python版本是3.6.1。
我檢查了xml.etree.ElementTree.Element
類,他們將來會更改它。 感謝John Gordon的提醒。
def __bool__(self):
warnings.warn(
"The behavior of this method will change in future versions. "
"Use specific 'len(elem)' or 'elem is not None' test instead.",
FutureWarning, stacklevel=2
)
return len(self._children) != 0 # emulate old behaviour, for now
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.