Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between getiterator() and iter() wrt to lxml

Tags:

python

lxml

As the question says, what would be the difference between:

x.getiterator() and x.iter(), where x is an ElementTree or an Element? Cause it seems to work for both, I have tried it.

If I am wrong somewhere, correct me please.

like image 543
user225312 Avatar asked Jun 19 '10 19:06

user225312


1 Answers

The Python documentation for ElementTree states that the getiterator() method has been deprecated starting with version 2.7 and says to use Element.iter(). The lxml API documentation states the same but also mentions that the implementation of getiterator() in lxml diverges from the original ElementTree behavior.

Interestingly enough the documentation also states that "If you want an efficient iterator, use the tree.iter() method instead". Note the word "efficient", which leads me to believe there is most certainly a difference in implementation between getiterator() and iter(), but without checking out the source I can't be 100% sure.

Anyhow, if something has been deprecated it's clear they don't want you to use it.

like image 166
Bruce van der Kooij Avatar answered Oct 21 '22 23:10

Bruce van der Kooij