开发者

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

开发者 https://www.devze.com 2023-01-03 21:09 出处:网络
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 b开发者_如何学运维oth, I have tried it.

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 b开发者_如何学运维oth, I have tried it.

If I am wrong somewhere, correct me please.


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.


getiterator is the ElementTree standard spelling for this method; iter is an equivalent lxml-only method that will stop your code from working in ElementTree if you need it, and appears to have no redeeming qualities whatsoever except saving you from typing 7 more characters for the method name;-).

0

精彩评论

暂无评论...
验证码 换一张
取 消