Разделить l xml etree на несколько объектов etree Python - PullRequest
2 голосов
/ 03 августа 2020

Есть ли функция для разделения набора дочерних элементов объекта etree на несколько объектов etree по индексу? Например, если бы мой узел root имел, скажем, 400 дочерних элементов, каждый из которых имел потомков, могу ли я получить 4 объекта etree из каждой секунды файла?

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
   

 

1 Ответ

1 голос
/ 03 августа 2020

Вы можете сделать это просто с помощью чего-то вроде

firstquarter = root.getchildren()[0:100]

et c.

...