ElementTree, fromstring() 错误 - AttributeError: 'Element' 对象没有属性 'getroot' [英] ElementTree, fromstring() error - AttributeError: 'Element' object has no attribute 'getroot'

查看:24
本文介绍了ElementTree, fromstring() 错误 - AttributeError: 'Element' 对象没有属性 'getroot'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 parse 函数来修改一个 xml 并且它起作用了,但是我尝试使用 .fromstring 并且它显示了一个错误

I was using parse function to modify a xml and it worked but I tried to use .fromstring and it showed an error

AttributeError: 'Element' 对象没有属性 'getroot'

AttributeError: 'Element' object has no attribute 'getroot'

这是代码的一部分.

AttributeError: 'Element' object has no attribute 'getroot'

推荐答案

这是因为 fromstring 方法已经返回了根对象.因此,无论您存储fromstring()"方法信息的 var 是什么,该 var 都是根.

This is because the fromstring method returns the root object already. SO whatever your var that stores the information form the "fromstring()" method is, that var is the root.

这篇关于ElementTree, fromstring() 错误 - AttributeError: 'Element' 对象没有属性 'getroot'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆