[lxml-dev] is tostring() confusing?

Stefan Behnel stefan_ml at behnel.de
Mon Jun 11 12:16:59 CEST 2007


Hi,

Christian Zagrodnick wrote:
> What I wonder about  is, why str(tree) or unicode(tree) isn't 
> supported. I see that str/unicode cannot have arguments (i.e. 
> pretty-print, encoding). But still there are suitable defaults, are 
> there not.

It's not really the defaults (plain UTF-8, sure), it's more of a concern about
having str() do something unexpectedly recursive.

You could argue that repr() should do a simple thing and str() should go for
recursion, but then, "print" calls str(), so that would flood your console
with UTF-8 stuff if you accidentally printed something for debugging.

Stefan



More information about the lxml-dev mailing list