gpt4 book ai didi

python - 如何在 Python 中获取 xml 文件的根节点?

转载 作者:数据小太阳 更新时间:2023-10-29 01:59:57 26 4
gpt4 key购买 nike

基本上我正在使用:

从 xml.etree 导入 ElementTree 作为 ET

path = 'C:\cool.xml'
et = ET.parse ( path )

但我不确定如何从 et 获取 root?

最佳答案

你可能想要:

et.getroot()

effbot site 查看 ElementTree 的官方文档.请注意,Python 2.5(第一个包含开箱即用的 ElementTree 的 Python 版本)使用 ElementTree 1.2,而不是更新的 1.3。区别不大,仅供引用以防万一。

关于python - 如何在 Python 中获取 xml 文件的根节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/687177/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com