【发布时间】:2016-03-29 19:56:19
【问题描述】:
当我使用文件 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' 对象没有属性 'tag'
with open(pelogPath,'r', encoding='utf-8') as f:
#xml = f.read()
root = objectify.parse(f)
print(root.tag)
【问题讨论】:
标签: python python-3.x io lxml.objectify