将 lxml etree 拆分为多个 etree objects Python
Split lxml etree into multiple etree objects Python
是否有一个函数可以将一个 etree object 集的 child 元素按索引拆分成多个 etree object?
例如,如果我的根节点有 400 children 每个都有后代,我可以从文件的每一秒得到 4 etree objects 吗?
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
你应该可以简单地用
之类的东西来完成
firstquarter = root.getchildren()[0:100]
等等
是否有一个函数可以将一个 etree object 集的 child 元素按索引拆分成多个 etree object? 例如,如果我的根节点有 400 children 每个都有后代,我可以从文件的每一秒得到 4 etree objects 吗?
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
你应该可以简单地用
之类的东西来完成firstquarter = root.getchildren()[0:100]
等等