[lxml-dev] is tostring() confusing?

Stefan Behnel stefan_ml at behnel.de
Sat Jun 9 22:37:21 CEST 2007


Hi Ian,

Ian Bicking wrote:
> Having tostring() as a function and not a method seems a bit odd to me. 
>   I know it's from ElementTree, but at least for HTML it's awkward -- 
> using lxml.etree.tostring on HTML is almost certain to create bad 
> output; the output won't be real XHTML (lacking namespaces and it'll 
> probably be invalid), and it will parse quite badly as HTML (<script 
> src="..."/> for instance will typically break the entire page in a browser).
> 
> When I was first using ElementTree, I remember being a bit baffled by 
> the lack of a serializing method.  I then found tostring and kind of 
> forgot about it, but as I copy tostring methods around (e.g., 
> lxml.html.tostring) it's starting to seem like a problem again.

I prefer keeping it the way it is in ET. After all, lxml.html is a module that
is based on the existing ET API in lxml.etree. It would feel funny to have it
one way in etree and another way in lhtml. It should be straight forward to
change from one to the other depending on the problem to solve and that
requires consistency.

Stefan


More information about the lxml-dev mailing list