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

Stefan Behnel stefan_ml at behnel.de
Sun Apr 6 16:32:40 CEST 2008


Hi,

Holger Joukl wrote:
> I suggest adding __float__, __int__ etc. methods 
> 
> to lxml.objectify StringElement, to enable things like
> 
> >>> float(objectify.DataElement("234"))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: float() argument must be a string or a number
> 
> These will just try to invoke the very same operation on the underlying pyval.

Ok with me, StringElement should behave as much like a string as possible.


> Maybe there are other classes where such methods would
> be helpful (BoolElement comes to mind, but I'll have to look).

You mean because of the int/bool duality in Python, but I don't think that's
something we should easily enable without a compelling use case. Remember that
it would mean converting the string value "true" to int(1), I don't think
that's obvious behaviour.


> Any objections? I can add this plus some tests otherwise.

Go ahead.

Stefan



More information about the lxml-dev mailing list