首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将lxml etree拆分为多个etree对象

将lxml etree拆分为多个etree对象
EN

Stack Overflow用户
提问于 2020-08-03 19:19:12
回答 1查看 78关注 0票数 2

是否有按索引将子元素的etree对象集拆分为多个etree对象的函数?例如,如果我的根节点有400个子节点,每个子节点都有后代,那么我可以从文件的每一秒中获取4个etree对象吗?

代码语言:javascript
复制
from lxml import etree as ET

tree = ET.parse('FileName.xml')
root = tree.getroot()

firstquarter = root.getchildren()   #function to get 0-100 of the child nodes
secondquarter = root.getchildren()  #function to get 101-200 of the child nodes
thirdquarter = root.getchildren()   #function to get 201-300 of the child nodes
fourthquarter = root.getchildren()  #function to get 301-400 of the child nodes
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-03 19:31:32

你应该可以简单地做一些类似的事情

代码语言:javascript
复制
firstquarter = root.getchildren()[0:100]

等。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63235642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档