ElementTree and clone element toot

Stefan Behnel stefan_ml at behnel.de
Mon Feb 9 08:20:35 CET 2009

Aahz wrote:
> In article <4986bfd7$0$9385$ba4acef3 at news.orange.fr>,
> m.banaouas <banaouas.medialog at wanadoo.fr> wrote:
>> Working with the ElementTree module, I looked for clone element
>> function but not found such tool:
> Have you tried using copy.deepcopy()?

While being the most obvious solution, calling deepcopy() on an Element is
surprisingly slow in ElementTree.


It's actually multiple times faster to rebuild the tree manually through
the API than to let deepcopy() do it. Fredrik also has written a little
factory for mass reproduction of Element trees.



More information about the Python-list mailing list