[issue5100] ElementTree.iterparse and Element.tail confusion

Fredrik Lundh report at bugs.python.org
Thu Mar 11 15:05:34 CET 2010


Fredrik Lundh <fredrik at effbot.org> added the comment:

Footnote: "iterparse" does things this way mostly to keep the implementation simple and fast; due to buffering, the tree builder are usually ahead of the event generation with up to 16k.  See the note on this page:

http://effbot.org/zone/element-iterparse.htm

and the message it links to for more on this topic.

Your case is a very common use case for "tostring", so it would probably have made sense to make "tostring" skip the tail on the element itself, at least if it's whitespace only.  Guess we could add an option...

But in your case, you can probably just nuke or normalize the "tail" element before writing it out (i.e. set it to None or "\n").

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5100>
_______________________________________


More information about the Python-bugs-list mailing list