当我使用文件 IO 而不是字符串 IO 时,为什么 lxml.objectify.parse 会失败?
以下代码有效:
with open(logPath,'r', encoding='utf-8') as f:
xml = f.read()
root = objectify.fromstring(xml)
print(root.tag)
以下代码失败并出现错误:
AttributeError:“lxml.etree._ElementTree”对象没有属性“标签”
with open(pelogPath,'r', encoding='utf-8') as f:
#xml = f.read()
root = objectify.parse(f)
print(root.tag)