[lxml-dev] Behaviour change in findtext

Aloys Baillet aloys.baillet at gmail.com
Fri Feb 20 05:10:41 CET 2009


Hi,
I was planning on upgrading to a recent version of lxml but found that our
code was failing in numerous places with None objects found in unexpected
places.
In lxml 2+ the findtext method will ignore the default and return None if
the element is found but the text is empty.
In elementtree and lxml before 2 the findtext method would never return
None, if the element is found but empty it would return the default.

Unfortunately I am unable to tell which exact version of lxml introduced
that change. And I am not sure if this change is by design, but I would say
it is not.

A proposed fix (if it is a bug...) is included in the attached unified diff.

Cheers,

Aloys
-- 
Aloys Baillet
Research & Development - Animal Logic
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/lxml-dev/attachments/20090220/53f93165/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: findtext_default_not_used_when_text_empty.diff
Type: application/octet-stream
Size: 366 bytes
Desc: not available
Url : http://codespeak.net/pipermail/lxml-dev/attachments/20090220/53f93165/attachment.obj 


More information about the lxml-dev mailing list