pythonElementTree解析的方法
pythonElementTree解析的方法
1、调用parse()方法,返回解析树
tree=ET.parse('./resource/movie.xml')
root=tree.getroot()
2、调用from_string(),返回解析树的根元素
data=open('./resource/movie.xml').read()
root=ET.fromstring(data)
3、调用ElementTree类的ElementTree(self,element=None,file=None)方法
tree=ET.ElementTree(file="./resource/movie.xml")
root=tree.getroot()
以上就是pythonElementTree解析的方法,希望对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
Python的缩进规则
和其它程序设计语言(如Java、C语言)采用大括号“{}”分隔代码块不同,Python采用代码缩进和冒号(:)来区分代码块之间的层次。在Python中,对于类...详情>>
2023-11-11 23:15:31
python五大异常处理机制
我们明白了什么是异常后,那么发现异常后怎么处理,便是我们接下来要解决的问题。这里将处理异常的方式总结为五种。1、默认异常处理机制“...详情>>
2023-11-11 22:02:33
python中any函数如何使用?
python中any函数如何使用?在python中,如果想要判断一个tuple或者list是否全部为空、0、False,可以使用any函数。使用any函数,当全为空、0、Fa...详情>>
2023-11-11 15:18:19
Python的信号库Blinker有何用法?
python的信号库Blinker有何用法?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。作为一个信号库,使用时候是支持一对一以及一对多...详情>>
2023-11-11 14:18:20