[lxml-dev] adding __float__, __int__ etc. to objectify.StringElement

Stefan Behnel stefan_ml at behnel.de
Wed Apr 9 09:02:44 CEST 2008


jholg at gmx.de wrote:
> Maybe the __int__, __float__ etc. methods should even go the
> the ObjectifiedDataElement class? So basically every explicit to-number
> conversion for data elements would work right out of the box, if the
> corresponding pyval class supports it.

They behave different for numbers and strings now, though.
int(string_element) will do a straight int(string_element.text), while
int(number_element) will first parse the number according to the type
rules and then convert the result to an int. I changed this for 2.1 as
int(element.text) will not work for non-int types such as a float string,
for example. I may even consider it a bug to be fixed in 2.0, but I find
it safer to leave the change for the new release series.


> For BoolElement, you'd need to override it anyway, as
> str(textOf(self._c_node))
> will not work for "true".

Same problem.

Stefan



More information about the lxml-dev mailing list