如何以相反的顺序打印所有findall元素?
labels = tree.findall(label)
for label in labels:
print etree.tostring(label)
答案 0 :(得分:3)
有一个reversed
功能:
for label in reversed(labels)
答案 1 :(得分:1)
或者可能是这样的:
labels = ET.findall(label)
alist =[]
for one_label in labels:
alist.append(etree.tostring(one_label))
print sorted(alist, reverse=True)