[lxml-dev] lxml.doctestcompare

Stefan Behnel stefan_ml at behnel.de
Thu Jun 7 14:15:11 CEST 2007


Hi Ian,

Ian Bicking wrote:
> I was trying to review some changes Stefan made

I was just refactoring. It's generally better to avoid isolated calls to

* el.xpath() -> use XPath() or, even better, el.getiterator() if possible

* el.attrib -> use el.set() and el.get()

Obviously, that's only in the cases where the replacement is equivalent. But,
for example, looping over "el.getiterator(tag)" is much faster than iterating
over "el.xpath('descendant-or-self:tag')". I actually think that code even
becomes simpler and thus more readable that way. For more advanced
expressions, XPath() allows you to use readable function names instead of the
less readable XPath expression.

Stefan



More information about the lxml-dev mailing list